Page 1 of 1

Change the Location of MySQL on cPanel

Posted: Thu Apr 12, 2018 9:55 am
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!

Re: Change the Location of MySQL on cPanel

Posted: Thu Apr 12, 2018 10:06 am
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

Re: Change the Location of MySQL on cPanel

Posted: Tue Apr 17, 2018 8:56 am
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!