Last week, I checked WHM (Web Hosting Management) server which used by this blog, Excellent website and Vavai.com due to an error messages regarding failed WHM update. After a few checking, it seems that root partition only left a bit free space and one of the largest folder is var/lib/mysql which contain a MySQL server databases. Before the partition getting lower and lower and would caused another problem, I decided to move the folder to another bigger partition.
The following are the processes which I have done to prevent further problem. Please note that while doing this setting, there will be a minimal down time (1-2 minutes). In this case, I prepare different partition on /dev/sdc1 which have approximately 100 GB free space and mounted to /srv/whm) :
- Go to WHM, choose Service Manager menu and uncheck on Monitoring MySQL option then click save. It’s an important step to prevent MySQL services to being automatically restart by WHM service monitor
- SSH or Putty to WHM console and run the following command :
mkdir -p /srv/backup/ chmod 777 -R /srv/backup mysqldump --all-databases | gzip > /srv/backup/alldatabases.sql.gz rsync -av /var/lib/mysql /srv/whm/ chown -R mysql:mysql /srv/whm/mysql /etc/init.d/mysql stop rsync -av --delete-after /var/lib/mysql /srv/whm/ mv /var/lib/mysql /srv/backup ln -s /srv/whm/mysql /var/lib/mysql /etc/init.d/mysql start
- Back again to WHM, choose Service Manager and check on monitoring MySQL then save
On the above step, I choose to take a safe precaution, so I back up the data using rsync command before moving the data. It would take longer steps but safer than the simple steps but has risk of data loss. If you feel confident, you can ignore the rsync command and just go through the instruction : Shutting down MySQL service, move the data into another folder, then make the symlink, and finally re-activate the MySQL services.
Actually, those instructions are should be applicable for non WHM MySQL server, for example, to move the mysql data on openSUSE / SLES server.