Home > Database > Mysql Tutorial > How to Safely Relocate Your MySQL Data Directory?

How to Safely Relocate Your MySQL Data Directory?

Susan Sarandon
Release: 2024-12-12 20:34:16
Original
836 people have browsed it

How to Safely Relocate Your MySQL Data Directory?

How to Relocate MySQL Data Directory

Is it possible to transfer my MySQL data directory to a different location? Will I still have access to my databases after the move?

Answer:

Follow these steps to change the MySQL data directory:

  1. Shut down MySQL:

    sudo /etc/init.d/mysql stop
    Copy after login
  2. Copy the current data directory:

    sudo cp -R -p /var/lib/mysql /newpath
    Copy after login
  3. Edit the MySQL configuration file:

    sudo gedit /etc/mysql/my.cnf 
    Copy after login
  4. Locate the "datadir" entry and modify its path to the new data directory.
  5. Edit the AppArmor profile:

    sudo gedit /etc/apparmor.d/usr.sbin.mysqld
    Copy after login
  6. Replace occurrences of "/var/lib/mysql" with the new path.
  7. Save and close the file.
  8. Restart AppArmor:

    sudo /etc/init.d/apparmor reload
    Copy after login
  9. Restart MySQL:

    sudo /etc/init.d/mysql restart
    Copy after login
  10. Log in to MySQL and confirm that you can access your previous databases.

The above is the detailed content of How to Safely Relocate Your MySQL Data Directory?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template