Resource icon

Change MySQL directory location

In this article we will learn to change the default location for MySQL directory to any other drive. We are assuming that there is a drive partition which is mount on /sdata directory in which we are moving our MySQL directory.

First of all, we have to disable and unmonitor the MySQL service from cPanel server.

Code:
# Login to WHM >> Service Manger >> uncheck “enabled” and "monitor".
# systemctl stop mysqld.service
mysql.png


Now, take the backup of MySQL directory first incase of any failure.

Code:
#cp -rp /var/lib/mysql /var/lib/mysqlbackup
#cp -rp /var/log /var/logbackup
Now, we have to run the below command. It will first move the MySQL directory to /sdata directory then create a symbolic link for mysql directory and finally change the ownership of mysql folder which is moved under /sdata folder.

Code:
# mv /var/lib/mysql /sdata && ln -s /sdata/mysql /var/lib/mysql && chown -R mysql:mysql /sdata/mysql
# rm -rf /tmp/mysql.sock && ln -sf /sdata/mysql/mysql.sock /tmp/mysql.sock
Now, update the mysql config file with new values

Code:
# vi /etc/my.cnf
Comment these below given values:

Code:
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
Add these new values:

Code:
datadir=/sdata/mysql
socket=/sdata/mysql/mysql.sock
Now, restart the MySQL and enable & monitor from WHM:

Code:
# systemctl restart mysqld.service
# Login to WHM >> Service Manger >> check “enabled” and "monitor".
Author
bhawanisingh
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from bhawanisingh

Top