Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Tuesday, June 07, 2016

Moving MySQL Data Folder on cPanel Environment

According to an advice from a cPanel engineer, the best way to move MySQL data folder to a different folder (e.g. on a different partition with more available disk space) on a cPanel / CentOS environment is to create symbolic link rather than modifying the my.cnf file.

Presuming that the original MySQL data folder is located on /var/lib/mysql and the partition with more available disk space is mounted as /home, these are the steps on how to move the MySQL data folder from /var/lib/mysql to /home/var_mysql/mysql.

1. Backup the whole MySQL database, just in case.

mkdir /home/backup (if it doesn't exist yet)
mysqldump --all-databases | gzip > /home/backup/alldatabases.sql.gz

2. Stop MySQL service and verify that it's stopped.

/etc/init.d/mysql stop
/etc/init.d/mysql status

3. Create destination folder, move the folder and all the files and subfolders from existing to new destination folder, change permission settings and create symbolic link.

mkdir /home/var_mysql
mv /var/lib/mysql /home/var_mysql
chown -R mysql:mysql /home/var_mysql/mysql
ln -s /home/var_mysql/mysql /var/lib/mysql


4. Start back MySQL service, and verify that it's started.

/etc/init.d/mysql start
/etc/init.d/mysql status

That's all. :)