An open-source database management system, MariaDB is commonly installed as part of the popular LEMP (Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. The data is managed by MariaDB by using a relational database and SQL (Structured Query Language). It acts as a fork of MySQL that is managed by the original MySQL developers. Since it’s designed as a replacement for MySQL, it uses commands that reference mysql and is the default package on CentOS 7.
This tutorial explains the installation of the latest version of MariaDB on a CentOS 7 server.
Prerequisites
To work as per this tutorial you will need –
A CentOS 7 with a non-root with sudo privileges.
Step 1 – Installation of MariaDB
In this tutorial yum will be used to install the MariaDB package, pressing y when prompted to confirm that we are ready to proceed.
1 |
sudo yum install mariadb-server |
After the installation is complete, start the daemon with the command as below –
1 |
sudo systemctl start mariadb |
As systemctl doesn’t display the outcome of all service management commands, the following command needs to be used to check whether the previous command was successful –
1 |
sudo systemctl status mariadb |
If the MariaDB was started successfully, the output should contain “Active: active (running)” and the final line needs to look like –
1 |
Dec 16 19:06:20 centos-512mb-sfo2-01 systemd[1]: Started MariaDB database server. |
Now, let’s check if MariaDB starts at boot using the systemctl enable command that will create the essential symlinks .
1 |
sudo systemctl enable mariadb |
1 2 3 |
Output Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. |
Step 2 – Securing the MariaDB Server
There’s a security script to change some of the less secure default options for things like remote root logins and sample users. Use the command below to run the security script –
1 |
sudo mysql_secure_installation |
You will get detailed information for every step with this script. Firstly, you will be prompted for the root password which hasn’t been set so press ENTER after its recommendation. Next you will be prompted to set that root password which you will need to insert.
Then accept all security suggestions by pressing Y and press ENTER for the remaining prompts that will remove anonymous users, disallow remote root login, remove the test database and reload the privilege tables.
Step 3 – Installation Testing
Installation can be verified and one can get information about it by connecting with the mysqladmin tool, a client that lets you run administrative commands. Use the command below to connect to MariaDB as root (-uroot), prompt for a password (-p) and return the version –
1 |
mysqladmin -u root -p version |
The output will be similar to this –
1 2 3 4 5 6 7 8 9 10 11 |
mysqladmin Ver 9.0 Distrib 5.5.50-MariaDB, for Linux on x86_64 Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Server version 5.5.50-MariaDB Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 4 min 4 sec Threads: 1 Questions: 42 Slow queries: 0 Opens: 1 Flush tables: 2 Open tables: 27 Queries per second avg: 0.172 |
This proves that installation is successful.