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.
Now, take the backup of MySQL directory first incase of any failure.
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.
Now, update the mysql config file with new values
Comment these below given values:
Add these new values:
Now, restart the MySQL and enable & monitor from WHM:
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
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
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
Code:
# vi /etc/my.cnf
Code:
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
Code:
datadir=/sdata/mysql
socket=/sdata/mysql/mysql.sock
Code:
# systemctl restart mysqld.service
# Login to WHM >> Service Manger >> check “enabled” and "monitor".