// Tutorial //

How To Install MariaDB on CentOS 7

Published on December 1, 2016
How To Install MariaDB on CentOS 7
Not using CentOS 7?Choose a different version or distribution.
CentOS 7


MariaDB is an open-source database management system, commonly installed as part of the popular LEMP (Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. 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’s 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 specifically need MySQL, see the How to Install MySQL on CentOS 7 guide. If you’re wondering about MySQL vs. MariaDB, MariaDB is the preferred package and should work seamlessly in place of MySQL.


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’ll use Yum to install the MariaDB package, pressing y when prompted to confirm that we wish to proceed:

  1. sudo yum install mariadb-server

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

  1. sudo systemctl start mariadb

systemctl doesn’t display the outcome of all service management commands, so to be sure we succeeded, we’ll use the following command:

  1. sudo systemctl status mariadb

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

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

Next, let’s take a moment to ensure that MariaDB starts at boot, using the systemctl enable command, which will create the necessary symlinks.

  1. sudo systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

Next, we’ll turn our attention to securing our installation.

Step 2 — Securing the MariaDB Server

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 for every step. The first prompts asks for the root password, which hasn’t been set so we’ll press ENTER as it recommends. Next, we’ll be prompted 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.

Finally, now that we’ve secured the installation, we’ll verify it’s working.

Step 3 — Testing the Installation

We can verify our installation and get information about it by connecting with the mysqladmin tool, a client that lets 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.

  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
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 indicates the installation has been successful.


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

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up now
About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Simple and easy-to-follow. I just switched to Centos 7 from Fedora, and this tutorial was exactly what I needed to start migrating my database file. Thanks!

Great tuto Melisa, thanks !!!

Hi, we update the droplet thinking the ram limit(1GB) it’s was the problem (now 2GB), but we have the same problem, mariadb in centos 7 is crashed many times in the same day. But i don’t have this problem in other server with the same centos and mariadb. i don’t kown what is the problem in digitalocean exactly. Check this link : https://www.digitalocean.com/community/questions/mariadb-5-5-sever-shuts-down-automatically-after-some-days-on-centos-7?answer=36254 , nobody can fix this problem. Where is the support people of DigitalOcean?

Try DigitalOcean for free

Click here to sign up and get $200 of credit to try our products over 60 days!
Try DigitalOcean for free