Tech News

How to install and secure MariaDB on CentOS 7 Server


MariaDB is an open source database management system. It uses a relational database and SQL to manage its data. MariaDB is a fork of MySQL managed by the MySQL developers. It's designed as an alternate for MySQL, uses some commands that reference mysql.




In this guide, we will walk you through the steps to install the latest version of MariaDB on a CentOS 7 server and some additional steps to secure its installation.


Prerequisites

To follow the steps mentioned in this article, you will need:
  • A CentOS 7 installed on (physical or virtual) machine with a non-root user with sudo privileges.


Installing MariaDB

To begin the installation process, we will use Yum to install the MariaDB package and dependencies, pressing y when prompted to confirm that we are sure to proceed:

sudo yum install mariadb-server

Once the installation is done, we will start the daemon using the following command:

sudo systemctl start mariadb

systemctl doesn't display the output of all service management commands, so to be sure we succeeded, we will use the following command:

sudo systemctl status mariadb

If MariaDB has successfully started, the output should contain "Active: active (running)` and the final line should look something like below:

Dec 01 19:06:20 centos-512mb-sfo2-01 systemd[1]: Started MariaDB database server.

To confirm that MariaDB starts when system boot, using the systemctl enable command, which will create the necessary symlinks.

sudo systemctl enable mariadb

Output
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

In the next step, we'll look into securing installation.


Securing the MariaDB Server

MariaDB comes with a security script to modify some of the less secure default options for things such as remote root logins and sample users. Use the following command to run the security script:

sudo mysql_secure_installation

The above script provides a detailed explanation of every step. The first prompts asks for the root password, which has not been set so we'll Hit Enter as it recommends. Next prompt asks to set that root password, which we'll do.

Then, we'll accept all the security suggestions by pressing Y and then Enter for the remaining prompts, which will remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables.

Since we've secured the MariaDB installation, now we'll verify whether it's working or not.


Testing the Installation

To verify MariaDB installation and get information about it we need to connect with the mysqladmin tool, a client that allows you run administrative commands.

Use the following command to connect to MariaDB as root (-u root), prompt for a password (-p), and return the version.

mysqladmin -u root -p version

You should see output similar to this:

Output
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

The above output indicates that, the installation was successful.





Conclusion

In this article, we've covered the basic steps to install and secure MariaDB on a CentOS 7 server.

No comments