How to Install MariaDB on CentOS 8

Published on

3 min read

How to Install MariaDB on CentOS 8

MariaDB is an open-source relational database management system, backward compatible, binary drop-in replacement of MySQL. It is developed by some of the original developers of MySQL and by many people in the community.

In this tutorial, we will explain how to install and secure MariaDB 10.3 on CentOS 8.

Installing MariaDB on CentOS 8

At the time of writing, the version of MariaDB available in the CentOS 8 repositories is 10.3.

Run the following command as root or user with sudo privileges to install MariaDB 10.3 on CentOS 8:

sudo dnf install @mariadb

The @mariadb module installs MariaDB server and all dependencies.

Once the installation is complete, start the MariaDB service and enable it to automatically start on boot by typing:

sudo systemctl enable --now mariadb

To verify that the MariaDB server is running, type:

sudo systemctl status mariadb

The output should show that the service is active and enabled:

● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-12-08 21:05:26 UTC; 15s ago

Securing MariaDB

MariaDB server package comes with a script called mysql_secure_installation performs several security-related operations, and sets the root password.

Run the script by typing:

sudo mysql_secure_installation

You will be prompted to set a password for the MariaDB root user. Once you do that, the script will also ask you to remove the anonymous user, restrict root user access to the local machine, and remove the test database. You should answer “Y” (yes) to all questions.

That’s it! You have installed and secured MariaDB on your CentOS server, and you’re ready to use it.

Connect to the MariaDB Shell

To connect to the MariaDB server through the terminal as the root account type:

mysql -u root -p

Enter the root password when prompted, and you will be presented with the MariaDB shell, as shown below:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 


In this tutorial, we’ve shown you how to install and secure MariaDB on CentOS 8, and how to connect to the MariaDB server from the command line.

Now that your MariaDB server is up and running and you can connect to the MariaDB shell, and start creating new databases and users .

CentOS 8 also provides MySQL 8.0. If you want to install MySQL instead of MariaDB, check the How to Install MySQL on CentOS 8 guide. Note that you cannot install both MariaDB and MySQL in the same server.

If you have any questions or feedback, feel free to leave a comment.