Move mySQL Directory to Home

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

Comments are closed.