MariaDB is a drop in replacement for MySQL and is an open source fork of MySQL created by the original MySQL developers. As of Red Hat Enterprise Linux (RHEL7) and CentOS 7 MariaDB is now the default SQL database, rather than MySQL which was the default in previous releases of the operating system.
Here we’re going to cover how to install and configure MariaDB.
MariaDB is available in the default RHEL/CentOS repository, though as is traditional with these operating systems the packages provided here will not be the most up to date version. For instance at the time of writing in August 2015 CentOS 7 will provide MariaDB 5.5.41 which was released in December 2014. The MariaDB repository provides the most up to date version, currently 5.5.45 which was released in August 2015. You can optionally generate repository configuration for the most up to date version of MariaDB here and install from the MariaDB repository.
MariaDB is simply installed with ‘yum’ as shown below. This is recommended over compiling from source or using RPM files, as MariaDB will be easier to update in the future through the package manager via ‘yum update’.
yum install mariadb mariadb-server -y
MariaDB should now be installed, we can confirm the package version installed as shown below.
[[email protected] ~]# mysql -V mysql Ver 15.1 Distrib 5.5.45-MariaDB, for Linux (x86_64) using readline 5.1
By default after installation MariaDB will not be running and will not start on boot as shown below.
[[email protected] ~]# systemctl is-active mariadb unknown [[email protected] ~]# systemctl is-enabled mariadb disabled
Using ‘systemctl enable’ and ‘systemctl start’ we can configure MariaDB to start on boot, and start the service now.
[[email protected] ~]# systemctl enable mariadb ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service' [[email protected] ~]# systemctl start mariadb
To confirm that we have enabled MariaDB and that the service is running perform these checks.
[[email protected] ~]# systemctl is-enabled mariadb enabled [[email protected] ~]# systemctl is-active mariadb active
Now that MariaDB is running you can access the command line by simply running ‘mysql’ as there is not yet any password in place, to keep the service secure it is important to set a root password with the ‘mysql_secure_installation’ command as shown below.
[[email protected] ~]# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: NewPasswordHere Re-enter new password: NewPasswordHere Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Now that the password has been set, you can access the command line with ‘mysql -u root -p’ at which point you will be prompted for the root password that you have just set.
MariaDB can be installed from the official RHEL/CentOS repositories, however you can install the most up to date version by adding the MariaDB repository. Yum can then be used to install the required packages. The MariaDB service should then be enabled to start during boot and then started up. By using ‘mysql_secure_installation’ the root password can then be set along with other base configuration.
I have found that MariaDB works great, I changed from MySQL 5.6 to MariaDB 10.0 earlier this year when the web server that runs this site was upgraded and have had no problems since converting, hopefully this guide will help you get started with MariaDB.
This post is part of our Red Hat Certified Engineer (RHCE) exam study guide series. For more RHCE related posts and information check out our full RHCE study guide.