Skip to content

Instantly share code, notes, and snippets.

@AkramiPro
Created February 3, 2023 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkramiPro/0598af6ba753847b5deb65d21bdf4ff2 to your computer and use it in GitHub Desktop.
Save AkramiPro/0598af6ba753847b5deb65d21bdf4ff2 to your computer and use it in GitHub Desktop.
WHM Move MySQL Data Folder
  1. Make a full mysqldump file
mysqldump --all-databases | gzip > /home/alldatabases.sql.gz
  1. Uncheck monitor in WHM > Service Manager for Mysql and save the area.

  2. Stop MySQL

/etc/init.d/mysql stop
  1. Make the directory for MySQL in /home, move it and symlink it
mkdir /home/var_mysql
mv /var/lib/mysql /home/var_mysql
chown -R mysql:mysql /home/var_mysql/mysql
ln -s /home/var_mysql/mysql /var/lib/mysql
/etc/init.d/mysql start
  1. Re-check monitor in WHM > Service Manager for MySQL and save the area

If anything goes wrong, you have the full mysqldump backup, and can use these steps to restore from it: First, you'll need the MySQL root password:

cat /root/.my.cnf

Once you have the password, then you can use this command to restore from that file:

gunzip < /home/alldatabases.sql.gz | mysql -u root -p

You'll be asked for the password here, so simply enter the one noted in /root/.my.cnf location.

Refrence: https://forums.cpanel.net/threads/how-to-move-mysql-data-directory.110481/post-709306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment