Skip to content

Instantly share code, notes, and snippets.

@ganey
Last active August 29, 2015 14:12
Show Gist options
  • Save ganey/15dfa929d6b35be34458 to your computer and use it in GitHub Desktop.
Save ganey/15dfa929d6b35be34458 to your computer and use it in GitHub Desktop.
cPanel mysql move to new mount point
#thanks to http://forums.cpanel.net/f354/how-move-mysql-data-directory-110481.html#post861642 and
#http://forums.cpanel.net/f354/how-move-mysql-data-directory-110481-p2.html#post1055762
#1. fallback dump
mysqldump --opt --all-databases | gzip > /home/alldatabases.sql.gz
#2. create new mount point
mkdir /var/lib/mysqltmp
#3. Configure /etc/fstab so that the new partition is mounted when the server boots (adjust values as necessary)
echo "/dev/sdb /var/lib/mysqltmp ext3 defaults,usrquota 0 1" >> /etc/fstab
#4. Mount the new partition. The following command will mount everything in /etc/fstab:
mount -a
#5. Change owner for mysql user
chown mysql:mysql /var/lib/mysqltmp
#6. change perms
chmod 711 /var/lib/mysqltmp
#6. check mount point (You should see a line that looks like this: /dev/sdb on /var/lib/mysqltmp type ext3 (rw,usrquota))
mount |grep /var/lib/mysqltmp
#7. sync data
rsync -vrplogDtH /var/lib/mysql/ /var/lib/mysqltmp/
#8. resync to backup again
rsync -vrplogDtH /var/lib/mysql/ /var/lib/mysqltmp/
#9. stop watchers
/scripts/restartsrv_tailwatchd --stop
/scripts/restartsrv_mysql --stop
#10. resync again
rsync -vrplogDtH /var/lib/mysql/ /var/lib/mysqltmp/
#11. move old dir for temporary backup purposes
mv /var/lib/mysql /var/lib/mysql.old
#12. recreate proper mount partition
mkdir /var/lib/mysql
#13. unmount new dir
umount /var/lib/mysqltmp
#14. change fstab line
vim /etc/fstab
#change to
# /dev/sdb /var/lib/mysql ext3 defaults,usrquota 0 1
#15. remount partition
mount -a
#16. check mount (You should see a line that looks like this: /dev/sdb on /var/lib/mysql type ext3 (rw,usrquota))
mount |grep /var/lib/mysql
#17. restart mysql and tailwatch
/scripts/restartsrv_mysql --start
/scripts/restartsrv_tailwatchd --start
# as a fallback unmount the new drive, and:
# mv /var/lib/mysql.old /var/lib/mysql
#as a bad fallback, restore from the sql dump
# gunzip < /home/alldatabases.sql.gz | mysql -u root -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment