Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Change the MySQL database directory  (Read 2917 times)

0 Members and 1 Guest are viewing this topic.

jominj

  • Guest
Change the MySQL database directory
« on: January 22, 2014, 06:27:21 am »
In cPanel servers, the default MySQl data directory location would be '/var/lib/mysql'. Sometimes, when /var partition become full, we need to move the MySQL data directory elsewhere.
1. Using df -h command, find out the partition which has enough space to contain MySQL data directory. For eg, let it be '/home'

2. Create a directory under that partition, for eg, '/home/mysql-data'

3. Rsync '/home/mysql-data' with  '/var/lib/mysql' directory.

Code: [Select]
# rsync -av /var/lib/mysql/ /home/mysql-data/ &
4. Once the initial Rsync is over, you have to stop the MySQL service in the server and then do a final Rsync. This is necessary because new data could be added to the already Rsync-ed databases while you perform the initial Rsync.

5. Once it is done, set up a symlink that points  '/home/mysql-data' to '/var/lib/mysql' . The advantage of setting up this symlink is that, even after changing the MySQl data directory, you don't have to update any MySQL variables.

6. Start MySQl service. It will work fine.