How To Install MariaDB on CentOS 7 – DigitalOcean

Introduction

MariaDB

is an open source database management system, commonly installed as part of the popular LEMP stack (Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl). It uses a relational database and SQL (Structured Query Language) to manage its data. MariaDB is a fork of MySQL managed by the original MySQL developers. It is designed as a replacement for MySQL, uses some commands that reference mysql, and is the default package on CentOS 7.

In this tutorial, we will explain how to install the latest version of MariaDB on a CentOS 7 server. If you need MySQL specifically, refer to the guide How to install MySQL on CentOS 7. If you are wondering about MySQL vs. MariaDB, MariaDB is the preferred package and should work smoothly instead of MySQL.

Prerequisites

To follow this tutorial, you will need:

  • A CentOS 7 with a non-root user with sudo privileges. You can learn more about how to set up a user with these privileges in the Initial Server Setup with CentOS 7 guide.

Step 1 — Installing

MariaDB

We will use Yum to install the MariaDB package, pressing and when asked to confirm that we want to continue

: sudo

  1. yum install mariadb-server

Once the installation is complete, we will start the daemon with the following command:

sudo systemctl

  1. start mariadb systemctl

it doesn’t show the output of all service management commands, so to be sure we’ve done that, we’ll use

the following command: sudo systemctl

  1. status mariadb

If MariaDB

started successfully, the output should contain ‘Active: active (running)’ and the end line should look similar to the following

: Dec 01

  1. 19:06:20 centos-512mb-sfo2-01 systemd[1]: The MariaDB database server started. Next

,

let’s take a moment to make sure MariaDB starts at boot, using the systemctl enable command, which will create the necessary symbolic links

.

  1. sudo systemctl enable

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

Next, we will focus our attention on securing our installation.

Step 2 — Secure the server

MariaDB

MariaDB includes a security script to change some of the less secure default options for things like remote root logins and sample users. Use this command to run the security script:

  1. sudo mysql_secure_installation

The script provides a detailed explanation of each step. The first few requests ask for the root password, which has not been set, so we will press ENTER as recommended. Next, we will be asked to set that root password, which we will do.

Then, we’ll accept all security hints by pressing Y and then ENTER for the remaining messages, which will remove anonymous users, disallow remote root login, delete the test database, and reload the privilege tables.

Finally, now that we

have secured the installation, we will verify that it works.

Step 3 — Test the

installation

We can verify our installation and obtain information about it by connecting with the mysqladmin tool, a client that allows you to execute administrative commands. Use the following command to connect to MariaDB as root (-u root), prompt for a password (-p), and roll back the version.

  1. mysqladmin -u root -p version You should

see output similar to this:

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 Localhost connection via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 4 min 4 sec Threads: 1 Questions: 42 Slow queries: 0 Apertures: 1 Emptying tables: 2 Open tables: 27 Queries per second Average: 0.172

This indicates that the installation was successful

.

Conclusion

In this tutorial, we have installed and secured MariaDB on a CentOS 7 server. To learn more about using MariaDB, this guide to learn more about MySQL commands can help. You can also consider implementing some additional security measures.