Restore MySQL datadir on a new server

Posted on May 20, 2017 at 6:50 pm

You can restore a previously copied\moved MySQL datadir on a new server:

1) Stop the MySQL service

service mysql stop

2) Rename the actual MySQL datadir to something different:

mv /var/lib/mysql /var/lib/mysql_original

3) Copy the MySQL datadir to restore in the MySQL datadir path:

cp -R /backups/mysql /var/lib

4) Set mysql:mysql permissions to the new /var/lib/mysql directory:

chown -R mysql:mysql /var/lib/mysql

5) Start the MySQL service

service mysql start

6) If all went well, remove /var/lib/mysql_original:

rm -rf /var/lib/mysql_original

Other Posts

Updated Posts