Move MySQL to new folder or hard drive

You will ofter comes across time when partition containing MySQL will started to fill up and you need to move it to  a new directory. So to move MySQL to new directory first of all stop the MySQL service
[bash]
[root@servertechsupport ~]# /etc/init.d/mysql stop
[/bash]
Note: If you are using cPanel Make sure you disable service check from WHM too. Login to WHM > Service Manager > Uncheck “Monitor” for MySQL
Now make sure that MySQL is not running. If the below command produce any output of mysql running then kill all those MySQL process and then proceed
[bash]
[root@servertechsupport ~]# ps aufx | grep -i mysql | grep -v grep
[root@servertechsupport ~]#
[/bash]
Now copy the MySQL data directory to new folder where you want to move the MySQL
[bash]
[root@servertechsupport ~]# mkdir /disk2/mysql
[root@servertechsupport ~]# chown mysql:mysql /disk2/mysql
[root@servertechsupport ~]# rsync -av –progress /var/lib/mysql/* /disk2/mysql/
[/bash]
Now edit the MySQL configuration file /etc/my.cnf and change the below settings. Add them if they are not present.
[plain]
[mysqld]
datadir=/disk2/mysql
socket=/disk2/mysql/mysql.sock
[/plain]
Now start the MySQL service.
[bash]
[root@servertechsupport ~]# /etc/init.d/mysql start
[/bash]
Now test your MySQL databases. If everything is running fine then you can delete your old /var/lib/mysql directory to free up disk space.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


2 × nine =