In this article, we have guided to move the MySQL data directory in CloudLinux CentOS 7.
Sometimes, databases outgrowing the space on the file system. To optimize server performance, adding more space is evaluating ways or taking advantage of other storage features. This article will guide you to move the MySQL data directory to a different directory.
1. Always keep backup. Take a full backup of the databases, using the following command:
# mysqldump –opt -uroot -proot_password > /tmp/mysqldump
2. Disable MySQL monitoring
whmapi1 configureservice service=mysql enabled=1 monitored=0
3. Stop MySQL service
# systemctl stop mysql.service
4. Make sure that the following parameters are present
Edit config file:
# vi /etc/systemd/system/mariadb.service.d/homedir.conf
Check the following values:
5. Next, let’s create an directory in /home path
# mkdir /home/mysql_data
Note: You can choose any directory name.
6. Now, move the MySQL data directory from the old path to the new path:
# mv /var/lib/mysql /home/mysql_data
Note: optionally, before you move the MySQL data directory, you can copy the directory into different locations or compress it. In case something went wrong, you would still have a backup of the mysql data directory.
7. Set ownership to the mysql directory
# chown -R mysql:mysql /home/var_mysql/mysql
8. Create an empty directory, where the socket file will be located
# mkdir /var/lib/mysql/
9. Set the ownership
# chown mysql:mysql /var/lib/mysql/
10. Now, modify MySQL config file to contain following directives
11. Remount CageFS system-wide
# cagefsctl –remount-all
12. Start MySQL service
# systemctl start mysql
13. Enable MySQL monitoring
whmapi1 configureservice service=mysql enabled=1 monitored=1
We have seen, how our support engineers move the MySQL data directory in CloudLinux CentOS 7.
[Need assistance to fix this error or install tools? We’ll help you.]