MySQL to MariaDB Migration Script

As of late it seems as if everyone is jumping on the MariaDB Database bandwagon. In this article I will provide a bash automation script as well as detail it’s usage in order to ease the MySQL Server to MariaDB Server migration. The script is broken down into four stages. Below I will break down each section and explain what it is doing.

Declare Variables

In this section it is pretty obvious that we are declaring the variables to be passed to the rest of the script. This section will need to be edited for your environment.

Migrate Function

This is the meat and potatoes of the entire script. In this function, once again we have four sub components stacked to run in a specific order.

  1. Export the database from the MySQL Server to a .dump file.
  2. Convert all tables from MyISAM to InnoDB and export to a .sql file.
  3. Create the database on the MariaDB Server using command line.
  4. Import the database .sql export into the MaraiaDB Server.

Migrate Databases

Again, this section is pretty self-explanatory in that it simply calls the migrate function with the database you would like to migrate. Note that you will need one statement for each database that will be migrated as seen in the example script.

Database Optimization

Lastly, we are calling mysqlcheck to optimize the newly created databases. Note, the output from the command is being redirected to a file called optimize.txt.

You may note in the script above there is no mention whatsoever about copying/creating users. The decision to for go creating users in this script is one that was intentional. If you are moving your databases to a new server, this would be a great time to audit you user base.

download-icon Migration Script Download

Did you find this article useful? Why not share it with your friends?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.