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:
Shut down MySQL:
sudo /etc/init.d/mysql stop
Copy the current data directory:
sudo cp -R -p /var/lib/mysql /newpath
Edit the MySQL configuration file:
sudo gedit /etc/mysql/my.cnf
Edit the AppArmor profile:
sudo gedit /etc/apparmor.d/usr.sbin.mysqld
Restart AppArmor:
sudo /etc/init.d/apparmor reload
Restart MySQL:
sudo /etc/init.d/mysql restart
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!