Change MySQL Data Directory: Relocating Your Databases
To modify the default MySQL data directory, it is crucial to follow a series of steps to ensure a seamless transition and maintain database accessibility.
Halt MySQL Services:
Start by stopping MySQL using the command:
sudo /etc/init.d/mysql stop
Data Directory Replication:
Duplicate the existing data directory, typically located at /var/lib/mysql, to the new desired location:
sudo cp -R -p /var/lib/mysql /newpath
Restart AppArmor:
Reload the AppArmor profiles using the command:
sudo /etc/init.d/apparmor reload
MySQL Service Restoration:
Restart MySQL:
sudo /etc/init.d/mysql restart
By completing these steps, you can successfully relocate MySQL's data directory to a new path while maintaining access to your databases.
The above is the detailed content of How to Safely Change the MySQL Data Directory?. For more information, please follow other related articles on the PHP Chinese website!