Move mySQL Directory to Home


Upon logging on to one of the servers this morning we found out the Cpanel was not working because it was complaining about / ran out of disk space

So doing a df indeed confirmed that /var folder was out of disk space and most the space was being taken up by mySQL Databases

So we needed to move this to /home and create a symlink for this

By default all mySQL database on a server is saved in /var/lib/mysql directory. If you don’t have enough space left in /var directory or if its filling up quickly, you can move your  directory to /home partition

so this is what we did

Login to SSH and do the following

//Make a backup of all databases
mysqldump --all-databases | gzip > /home/backupdatabases.sql.gz

//Stop mysql
/etc/init.d/mysql stop

//Create a new mysql directory in home
mkdir /home/mysql

//move mysql from current location to new location
mv /var/lib/mysql /home/mysql

//Set Permissions
chown -R mysql:mysql /home/mysql/mysql

//create a symlink
ln -s /home/mysql/mysql /var/lib/mysql

//restart mysql
/etc/init.d/mysql start

and there you go :) nice space freed up and all back to normal



One comment on “Move mySQL Directory to Home

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s