How to replace MySQL with MariaDB on CentOS 6


Mariadb-seal-shaded-browntext-plainsvg.svgIn this article we will explain how to replace your MySQL server with MariaDB 5.5 database on your CentOS 6 server which is very simple. MariaDB is a fork of the MySQL source code. It is free and open source, drop-in replacement for MySQL led by the original developers of MySQL. MariaDB is widely used and several Linux distributions and large companies have already switched from MySQL to MariaDB.

First of all, you should always have a backup of all existing MySQL databases:

# mysqldump --all-databases --user=root --password --master-data > /root/backup.sql
Enter password:

Stop your MySQL service by executing the following command:

# service mysqld stop
Stopping mysqld:             [  OK  ]

Remove all installed MySQL packages:

# yum -y remove mysql*

Even if we removed MySQL, your current MySQL configuration file (my.cnf) is saved as /etc/my.cnf.rpmsave and it can be used later.

Using your favorite text editor create a repository file /etc/yum.repos.d/mariadb.repo containing the following lines:

32bit systems:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

64bit systems:

[mariadb]
name = MariaDB 
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Now you can install MariaDB using YUM. Ecexute the following commands:

# yum update
# yum install -y MariaDB-server MariaDB-client MariaDB-devel

After the installation is completed, start MariaDB:

# service mysql start
Starting MySQL.. SUCCESS!

Restore your old my.cnf file:

cp /etc/my.cnf.rpmsave /etc/my.cnf

That’s all. At this point you have successfully replaced MySQL with MariaDB.

# mysql -V
mysql  Ver 15.1 Distrib 5.5.33a-MariaDB, for Linux (i686) using readline 5.1

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script.
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Tutorials
How to install phpBB 3 on a CentOS 6 VPS
Tutorials
How to install Zenphoto Gallery CMS on a CentOS 7 VPS
Tutorials
Install Odoo 9 on Ubuntu 14.04
  • ron

    ronron

    Author Reply

    One thing that I ran across that might be worth mentioning here. If you have packages that you want to keep such as mysql-workbench-community, mysql-connector-python, that work fine with mariadb by the way, then instead of:
    yum -y remove mysql*
    you can remove just the main packages:
    rpm --nodeps -e mysql-utilities mysql-devel mysql-libs mysql-server
    Install the mariadb as described here. Then, I checked workbench to see if it was ok and it couldn’t fetch the tables, views, procedures, etc. I had to run this command to fix things:
    mysql_upgrade -uroot -p -h 127.0.0.1
    After that everything worked fine. Good post though!