Change the Location of MySQL on cPanel

Discussions related with hosting control panels used, which include cPanel, Plesk, Directadmin etc..

Moderator: Staff

Post Reply
jeniffer
Posts: 0
Joined: Wed Sep 21, 2016 3:23 pm

Change the Location of MySQL on cPanel

Post by jeniffer »

Hi,

My data folder(mysqldata) is in the / var / partition, and because this partition keeps getting filled, I would like to move my data folder.

My server is a Cpanel server, I tried adding a symbolic but it isn't working for me.

Any help?
Many thanks!


stark
Posts: 0
Joined: Fri Sep 16, 2016 10:00 am

Re: Change the Location of MySQL on cPanel

Post by stark »

Hi Jenni,

Did you follow this steps to change the mysql path ?

https://forums.cpanel.net/threads/how-to-move-mysql-data-directory.110481


Brandon N
Posts: 0
Joined: Thu Apr 05, 2018 11:19 pm

Re: Change the Location of MySQL on cPanel

Post by Brandon N »

You can follow below steps to change location of MySQL on cPanel

1) First you need to backup the current folder of MySQL data, so that if anything goes worse we can restore it

You can execute below command for creating backup

tar -cvf mysqldata.tar /var/lib/mysql

2) Then we need to change the default directory which is /var/lib/mysql to new one. For example, if you are moving MySQL from /var/lib/mysql to /home/mysql/

For that In the [mysqld] section of /etc/my.cnf, add/modify this line:

datadir=/home/mysql

Don't restart MySQL yet.

3) Now migrate the data from old location to new location, For that you need to stop mysql process by following command

service mysql stop

then sync the data,and start it up again by following command

service mysql start

Here's the command to sync with the example of MySQL being moved to /home/mysql:

rsync -avz /var/lib/mysql/ /home/mysql/

Now, re-link the socket:

ln -sf /home/mysql/mysql.sock /tmp

4) Restart MySQL

Since you already added the datadir entry to my.cnf, all you need to do is restart again and everything should be working.

Brandon N
Linux Support Engineer.
Nixtree Solutions
Managed Full Server Backups
https://www.nixtree.com/managed-backups.php
Follow us on : https://twitter.com/nixtree

Do you need professional help with this? Please open a support ticket to support@nixtree.com we'll fix it for you!


If you are looking for assistance in server management, please get in touch with our support.
Post Reply