On this tutorial, we’ll present you methods to set up, configure and optimize MariaDB on CentOS 8. It is a beginner-friendly step-by-step tutorial. It also needs to work on different CentOS variations.

MariaDB A popular alternative to MySQL is that many people are migrating their databases.


There are really no prerequisites, other than owning a CentOS 8 server (which was written for this tutorial) and root access to the server itself. You can get a cheap $ 2.5 per month on a CentOS server on JMSOLUTION.

Step 1: update your system

The first thing you should always do is update your system. Run the following command:

yum update -y

Step 2: Install MariaDB

To install the version included in the CentOS 8 repository by default, run the following command:

yum install mariadb-server -y

This will install MariaDB Server 10.3 (as of writing).

If you want to use a newer version (eg 10.5, the current latest stable release), run the following command:

wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup

This will run the mariadb_repo_setup bash script which adds a repository so that you can get the latest version.

After running the script, install a new version with the same command as before:

yum install mariadb-server -y

Step 3: Start Mariadb, enable on boot, and check which version you are using

The next step is to start the MariaDB service:

systemctl start mariadb

And enable MariaDB to start at boot:

systemctrl enable mariadb

To check which version you are using, log into MariaDB with the following command:


And use this command to check the version you are using:


This should give you similar results:

MariaDB [(none)]> SELECT VERSION();
| 10.5.8-MariaDB |
1 row in set (0.000 sec)

Step 4: Secure MariaDB

To protect MariaDB, the following script must be run after installation:


This script will prompt you with many options, all of them are well documented and self-explanatory.

Running this script is only a small step to secure MariaDB. You should still secure the servers, and read more information about them Official docs.

Alternative steps

These are alternative steps to improve MariaDB:

Check and repair your MariaDB

If you want, you can run mysqlcheck to check (and repair) your database. To check all databases, run:

mysqlcheck -A

You can perform the command -auto-repair to automatically repair when the check-table is broken:

mysqlcheck -A --auto-repair

Run MySQLTuner to get additional suggestions

Is a pearl MySQLTuner The script that you can run and the script can give you many recommendations to improve the performance and security of your Mariadb.

To run the script, first install Perl if it is not already installed:

yum install perl -y

Download the script:

wget http://mysqltuner.pl/ -O mysqltuner.pl

And play it:

perl mysqltuner.pl

Just a heads up: This script will only suggest you what you should do, the script will not make any real recommendation for you.

Upgrade mariaDB to a new version

If you are upgrading from a version like 10.4 to 10.5 then these instructions will work, but the instructions are the same for other cases as well.

First, update the yum repository. Either run the yum update command or rerun the mariadb_repo_setup script from step 1 or 2.

Then, stop the service:

systemctl stop mariadb

Next, remove and run MariaDB:

yum remove mariadb-server -y

And now you can install the new version by running the command from step 2.

Then, resume MariaDB:

systemctl start mariadb

And finally, run mysql_upgrad to check if everything is compatible with the new version with the following command: