- Linux Training
- Desktop Tutorials
- Server Tutorials
|MySQL to Maria DB Migration|
|Server - Server Management|
With Oracle's fairly recent acquisition of MySQL, a lot of people are looking to move away from MySQL in fear of Oracle changing the licensing, which could force you to change database backends. As such, today we'll migrate from MySQL to MariaDB, which is a popular alternative to MySQL. MariaDB was initially forked in January of 2009. We can make this transition quickly, but not without some downtime, as we can't have both databases working on the same files simultaneously. These instructions are good for all popular distributions of GNU/Linux, however Debian 7 (Wheezy) will be used in the reference code shown.
This process only works reliably if you are running the same major version of MySQL as MariaDB. Currently this means you must be running MySQL 5.5 and intend on moving to MariaDB 5.5.
First and foremost, shut down all processes that use MySQL. You can't move the database around while it's in use. Doing this is far beyond the scope of this article, but since it is your system, hopefully you have a good idea about what all is running on your server, and can shut processes down appropriately. It is advised to stop MySQL by hand, rather than depending on your package manager to do it for you.
# service stop apache2
# service stop nginx
# service stop mysql
Next, make a simple mysqldump of your current databases. These commands dump every SQL database you have to a single file. Make sure you do this on a partition big enough to hold your data. Doing this in /tmp is a very bad idea.
# cd /backups
We are now done with MySQL. Use your package manager to remove it. Do not worry about associated libraries, as MariaDB is a drop in replacement. It should remain compatible at the API layer. If your package manager tries to uninstall half the system, cancel the operation and proceed to the next step. apt based distributions will probably want to remove all kinds of things, but since nothing is installed on our test system, this doesn't happen so it's safe to remove in our example.
# apt-get remove mysql-server-core-5.5 mysql-server-5.5 mysql-server mysql-common mysql-client-5.5 libmysqlclient18
Next, add the MariaDB repositories, and install it. Instructions for your distribution can be found at:
If, in the prior step your package manager wanted to uninstall everything, that means it wants to do this upgrade in-place. Installing the new MariaDB packages should have simply overwritten the old MySQL packages, as your package manager sees it as any other upgrade.
# apt-get install mariadb-server
Some package systems start what they install automatically, but some don't. If not, start up MariaDB now, and verify its sanity.
# mysql -u root -p -Be 'show databases'
This next part won't be pretty, but it shouldn't be tricky. The configuration has changed considerably between MySQL and MariaDB, however it is extremely easy to work through. Most everything that changed is related to mechanisms that have been replaced, such as how replication works. You should be safe in simply copying over the performance tuning options you set in MySQL's my.cnf, and reconfiguring the rest by hand. For small databases with less intricate setups, it is likely that you won't need to do any thing more than copy the performance options that you've changed.
bind-address = 127.0.0.1max_connections = 10
Start up MariaDB again and verify sanity once again. Once you've done that and stopped MariaDB, start it up once more, as you normally would through your init system. Note that MariaDB shares the same name for compatibility.
# service restart mysql
Lastly, start up the applications that use a SQL database.
# service apache2 start
At this point you're done! There is no conversion of your databases when switching to MariaDB, so if for whatever reason you don't like it, you can freely switch back to MySQL.
# service mysql stop
Article by Michael "mngrif" Griffith