How to Safely Change Location of the MySQL Data Directory (partition/disk)

Most Used Cases are:
– Useful for migration of the MySQL to SSD Disk and to get the best performances.
– Useful if you are out of the disk space on your partition or a disk.

In this tutorial we will move MySQL to the /home folder.

First Make the Backup of all databases

mysqldump --add-drop-table --all-databases | gzip > /home/alldatabases.sql.gz

Lets start migrating MySQL

service mysqld stop
cd /var/lib
mv mysql /home/mysql
ln -s /home/mysql mysql
chown -R mysql:mysql /home/mysql
service mysqld start

That is it, no other changes are required.

CloudLinux & CageFS
If you are running CloudLinux then you will need to update CageFS skeleton.
Once you have done migration proceed with:

/usr/sbin/cagefsctl -u