These are the steps to move MySQL Database Files to a different drive. I had to do this in the week to help someone out, thought this would be a good tip. The default database location is /var/lib/mysql, this was not changed when the consultant installed the system.
Stop MySQL and ensure the processes are down
systemctl stop mysql ps -ef | grep -i mysql
Move the where the files are now
cd /var/lib/
Copy all the files to your new location
cp -rp mysql /data/
Edit the location in the main configuration file to your location
vi /etc/my.cnf
Look for the datadir line, edit to your new location
datadir=/data/mysql
Start MySQL
systemctl start mysqld.service
Checks the time stamps on the new files and the old files, this will verify its all moved
Login to the database and check
mysql -u root -p
Some of the Stop and starts may vary depending on what version of Redhat or Linux you are using.
I am always interested in feedback so please feel free to add any comments, or you can mail me here. If you would like to submit a quick tip with full credit and links back to your site then also feel free to contact me.
