PDA

View Full Version : How to move mysql folder to another partition or server?



Fli
11-02-2014, 03:44 PM
Hello,

if partition "/" where /var/lib/mysql is located is low on disk space, one can move mysql folder to another/bigger partition or on another server

Basically its about stopping mysql, copying data and then creating symbolic link from old location to new location..

See the free disk space in various locations:

df -h

if /home has enough space, you may create dir in /home/mysql

mkdir /home/mysql

set proper permissions to that directory

chown mysql:mysql /home/mysql

2 times execute copying data from old to new location

rsync -vrplogDtH /var/lib/mysql/ /data/mysql/

stop mysqld:
if WHM server is in place make sure mysql is not auto-restarted by your control panel (Untick WHM/Service Configuration/Service Manager mysql monitoring)
then:

/etc/init.d/mysqld stop

copy data again:

rsync -vrplogDtH /var/lib/mysql/ /home/mysql/

rename old mysql directory and instead add symlink to new location:

mv /var/lib/mysql /var/lib/mysql.old;ln -s /home/mysql /var/lib/mysql

start mysql

/etc/init.d/mysqld start

if any error, put it into google..

How to move mysql to another server with fast HDD? Probably with help of rsync and scp. Then after coppied, stop source mysql, do second rsync, change mysql server to the remote server.