Move mysql to home

From Cheatsheet
Jump to navigation Jump to search


Info: If space and time permits, do a fresh dump of all databases

{{#lst:MySQL_Commands|dump_all_dbs}}


Notice: In this example we will be going from /var/lib/mysql/ to /home/mysql.datadir/ - adjust as necessary


Warning: You should only put MySQL's data directory in an empty location


Notice: CLOUD LINUX - If the server is running cloud linux with cagefs, you need to update the new mount point in /etc/cagefs/cagefs.mp http://docs.cloudlinux.com/mount_points.html

First, create the new datadir:

mkdir -p /home/mysql.datadir/
chown mysql:mysql /home/mysql.datadir/
chmod 751 /home/mysql.datadir/

Sync things:

rsync -aHlP /var/lib/mysql/ /home/mysql.datadir/

Sync it a few times, and run it one last time right before you do the final sync/switch.

Then, when you're done:


/usr/local/cpanel/bin/tailwatchd --stop
/etc/init.d/crond stop
/etc/init.d/mysql stop



Warning: It is important to check that mysql actually shuts down. Moving it while it remains running, or having it start up while you are moving it can lead to data corruption.


ps aux |grep mysql
netstat -tpln | grep mysql


After you have confirmed it is down, you can proceed with a final sync and then finally move it. You can run the rsync twice to confirm the final sync has completed as no data will be transferred on the second sync.


rsync -aHlP /var/lib/mysql/ /home/mysql.datadir/
mv /var/lib/mysql /var/lib/mysql.lwold
ln -s /home/mysql.datadir /var/lib/mysql
/etc/init.d/mysql start
/usr/local/cpanel/bin/tailwatchd --start
/etc/init.d/crond start



Info: Once the move is done, you should update the my.cnf and put in the new datadir location.
datadir=/home/mysql.datadir 


Notice: If CloudLinux with CageFS, run
 cagefsctl --remount-all
before restarting MySQL.



Notice: You should now check the mysql error log, and check and see how it booted up. If it went well, you should be set, and you can then remove the old datadir



Warning: If you moved MySQL's datadir to free up space on /var/, you should now remove the old mysql datadir



Warning: If you do this on a shared server, you also need to adjust the backup script to point to the new location. /usr/local/lp/configs/backup/backup-config.xml
<target type="fileOrDir" destination="home/mysql">
    /home/mysql
</target>


Warning: Guardian Customers: If the customer has guardian backups with the mysql plugin you will need to update the plugin with the correct mysql directory.