Migrating MySQL to a new server

When you need to migrate a MySQL server instance to a new server for any reason, eg upgrade of hardware, distri upgrade,… you can easily do the following:

Migrating the databases
On the “old” mysql server, you need to export all databases by:

Copy your sql dump file with eg rsync

On the new server, import your dumps:

Migrating the users

If you are migrating to the same MySQL version you can export all users and settings by dumping the mysql database itself.

and just copy & import of that file on the new server

However, when doing a MySQL version upgrade, we need to export all the Users and their privileges.

Here’s an easy bash script to do this.

Copy the lines between the ———————-

Login on your new server, go to the mysql shell via the admin user

And paste the output from our previous script.

Et Voila, your databases and users are migrated!

 

Leave a Reply

Your email address will not be published. Required fields are marked *