Move MySQL Directory in WHM \ cPanel

We originally installed an image from the cPanel website. The /root parition holds the system information and the /data  houses the users  web and mail data. Unfortunatley the /root partition is NOT installed as an LVM which makes it difficult to expand. What I did notice is that the users MySQL data is actually stored in the /root partition. As this was the majority of the data I decided to move this to the /data partition:

 

 

 

1. Backup the databases

mysqldump --opt --all-databases | gzip > /data/alldatabases.sql.gz

(as our cPanel server is a VPS we are able to take a snapshot)

 

2. Stop monitoring  the MySQL service

WHM -> Service Manager -> Uncheck "Monitor" MySQL Server

 

3. Stop MySQL

/etc/init.d/mysql stop

 

4.  Move the MySQL data 

i)  Make the new directory
 

mkdir /data/var_mysql

 

ii) move the data from old partition to new partition
 

mv /var/lib/mysql /data/var_mysql

 

iii) Change permissions on new directory

chown -R mysql:mysql /data/var_mysql/mysql

 

 

5.  Symbolically link old directory to new directory

ln -s /data/var_mysql/mysql /var/lib/mysql

 

6. Start MySQL

/etc/init.d/mysql start