Move mysql to home: Difference between revisions

From Cheatsheet
Jump to navigation Jump to search
Created page with "Category:MySQL {{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 '''..."
 
No edit summary
 
Line 6: Line 6:
{{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}}
{{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:
First, create the new datadir:
<source lang='bash'>
 
mkdir -p /home/mysql.datadir/
mkdir -p /home/mysql.datadir/
chown mysql:mysql /home/mysql.datadir/
chown mysql:mysql /home/mysql.datadir/
chmod 751 /home/mysql.datadir/
chmod 751 /home/mysql.datadir/
</source>
 
Sync things:
Sync things:
<source lang='bash'>
 
rsync -aHlP /var/lib/mysql/ /home/mysql.datadir/
rsync -aHlP /var/lib/mysql/ /home/mysql.datadir/
</source>
 
Sync it a few times, and run it one last time right before you do the final sync/switch.
Sync it a few times, and run it one last time right before you do the final sync/switch.


Then, when you're done:
Then, when you're done:


<source lang='bash'>
 
/usr/local/cpanel/bin/tailwatchd --stop
/usr/local/cpanel/bin/tailwatchd --stop
/etc/init.d/crond stop
/etc/init.d/crond stop
/etc/init.d/mysql stop
/etc/init.d/mysql stop
</source>
 


{{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.}}
{{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.}}


<source lang='bash'>
 
ps aux |grep mysql
ps aux |grep mysql
netstat -tpln | grep mysql
netstat -tpln | grep mysql
</source>
 


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.
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.


<source lang='bash'>
 
rsync -aHlP /var/lib/mysql/ /home/mysql.datadir/
rsync -aHlP /var/lib/mysql/ /home/mysql.datadir/
mv /var/lib/mysql /var/lib/mysql.lwold
mv /var/lib/mysql /var/lib/mysql.lwold
ln -s /home/mysql.datadir /var/lib/mysql
ln -s /home/mysql.datadir /var/lib/mysql
/etc/init.d/mysql start
/etc/init.d/mysql start
/usr/local/cpanel/bin/tailwatchd --start
/usr/local/cpanel/bin/tailwatchd --start
/etc/init.d/crond start
/etc/init.d/crond start
</source>
 


{{info|Once the move is done, you should update the my.cnf and put in the new datadir location.}}
{{info|Once the move is done, you should update the my.cnf and put in the new datadir location.}}

Latest revision as of 04:00, 11 April 2016


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.