MariaDB is a high performance drop-in replacement for MySQL, developed by some of the original authors of the MySQL project. This how-to will walk you through uninstalling MySQL and then installing MariaDB from their repository using the YUM package manager.
Removing MySQL
WARNING: Make sure to back up any databases you would like to keep, before you remove MySQL. Otherwise they may be lost forever!
The first step is removing MySQL using YUM.
- yum remove mysql*
(The * is a wildcard, and tells YUM to remove all packages starting with the string "mysql".)
In my case the list of packages that will be removed is:
- mysql
- mysql-devel
- mysql-libs
- mysql-server
- perl-DBD-MySQL
(The last package is removed as a dependency.)
This will backup the old mysql.log from /var/log/mysqld.log to /var/log/mysqld.log.rpmsave, and your MySQL config my.cnf from /etc/my.cnf to /etc/my.cnf.rpmsave. You can restore the MySQL config file later (by simply renaming it back) if you would like to use it for MariaDB.
Comatibility with Remi PHP packages
This is important if you are installing PHP-FPM from the Remi repository (for an example following our how-to/tutorial). There is a compatibility issue that needs to be addressed before you proceed with installing MariaDB:
Install the following package from Remi test:
- yum --enablerepo=remi-test --disablerepo=remi install compat-mysql55
A big thanks goes to malinens over at askmonty.org for pointing this out.
If you have made the mistake of installing MariaDB prior to discovering this issue, and getting an error similar to this upon starting PHP-FPM:
- NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: symbol mysql_client_errors, version libmysqlclient_18 not defined in file libmysqlclient.so.18 with link time reference in Unknown on line 0
You need to remove all mysql related packages from your system first:
- yum remove mysql-server mysql-libs mysql-devel mysql*
This will remove among others all the MariaDB packages, and php-mysql.
Next, install the compat-mysql55 package as instructed above - making sure to use the enable/disable repo commands to only get this particular package from the test repo.
Once that is done, proceed with re-installing MariaDB as per the instructions below, along with php-mysql (yum install php-mysql).
Installing MariaDB
First, let's add MariaDBs repository. Create the file /etc/yum.repos.d/MariaDB.repo by opening it in your favorite editor. We will use vim here, but nano might be easier if you are new to Linux (yum install nano, then nano -w filepath).
- vi /etc/yum.repos.d/MariaDB.repo
- [mariadb]
- name = MariaDB
- baseurl = http://yum.mariadb.org/5.5/centos6-x86
- gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
- gpgcheck=1
You should note that the last part of the baseurl needs to match your CentOS version and arch. In my case this would need to be centos6-amd64, for a 64-bit install, but since x86 (32-bit) is more common I've left that in the example above.
Save the file and exit your editor. (In vim this is done by holding Shif and pressing : (colon), entering "wq" (without the quotes) for "write quit", and enter.)
Moving on to installing the components using YUM:
- yum install MariaDB-server MariaDB-client
- //This will install:
- MariaDB-client
- MariaDB-server
- MariaDB-common
- MariaDB-compat
(The last two being dependencies.)
Now that it is installed, let's start the service:
- # service mysql start
- Starting MySQL.. SUCCESS!
Next, we secure the installation:
- # mysql_secure_installation
This will run you through securing the installation, and you should read each step carefully. I recommend that you set an appropriate root password, remove anonymous users, disallow remote root login, and remove the test database and access. Reload the privilege tables if you do.
Note: If you had a MySQL server running before you started, and uninstalled the MySQL database prior to installing MariaDB, the old data files should still be there. In that case the mysql_secure_installation procedure will fail if you try to feed it a blank root password... providing you have previously secured your MySQL install. You can then either skip running the script, or you can re-run it by supplying the previously set root password from the MySQL install.
Next you will want to set MariaDB to start on boot:
- # chkconfig mysql on
- And restart the MariaDB server:
- # service mysql restart
- Shutting down MySQL. SUCCESS!
- Starting MySQL.. SUCCESS!
Let's try to connect, shall we?
- # mysql -uroot -p //Enter your database root password when promted.
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 2
- Server version: 5.5.29-MariaDB MariaDB Server
- Copyright (c) 2000, 2012, Oracle, Monty Program Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]>
All done! Enjoy your new MariaDB server.
1.MariaDB