Moving MySQL Data directory from /var/lib to /home

Tags: cPanelMySQLsoftlink

Published on: September 14, 2014 by George K.

Moving MySQL Data directory from /var/lib to /home


Sometimes due to lack of Disk space in /var various activities such as logging gets affected and it may have severe impact on service and server uptime. In some cases, it is observed that default MySQL installation occupies large chunk of space in the /var partition due to the db data present in the default MySQL data  directory /var/lib/mysql.

Here we are  discussing the necessary steps to move mysql data directory location from /var/lib to /home without changing the configuration file.  Of course the ideal way is to change the data directory variable in /etc/my.cnf. This is just a work around utilizing the property of soft links to avoid downtimes and application configuration changes.

1) Stop MySQL

root@server [/var/lib]# /etc/init.d/mysql stop

2) Go to WHM -> Service Manager -> Uncheck  MYSQL service to disable it. 

Uncheck Enabled and Monitor against mysql



3) Copy the entire mysql data directory ( I assume that this is a default installation, verify the configuration file /etc/my.cnf for verification)  from /var/lib to /home by preserving the ownership, timestamps etc

root@server [/var/lib]# cp -pR mysql /home/

4) Move/Rename the mysql directory in /var/lib for the sake of backup

root@server [/var/lib]# mv mysql mysql_bak

5) Create Softlink in /var/lib to /home

root@server1 [/var/lib]# ln -s /home/mysql mysql

6) Restart MySQL

root@server [/var/lib]# /etc/init.d/mysql start

7) Enable Mysql service in WHM

Once the MySQL server is up, you may either  delete or move the previous mysql directory from /var/lib to somewhere else to free space on /var partition.

Get 24/7 expert server management

Category : cPanel, Howtos, MySQL, Troubleshooting

George K.

George K.

George started his career in web hosting and Linux technical support in the year 2004 and is with SupportSages since 2009. He has keen interest in server optimizations, custom security solutions, hacked server recovery, cyber forensic and high availability fail over system design and implementation. George loves long drives and is passionate about art and literature.

You may also read:


Add new commentSIGN IN

Let's Connect

Get new updates


$0.000 items