Oct 11, 2023 6 min read

How to Install MariaDB on CentOS 8

Install MariaDB on CentOS 8 with our step-by-step tutorial. MariaDB is an open-source RDBMS commonly used in web applications and enterprises.

Install MariaDB on CentOS 8
Table of Contents

Choose a different version or distribution


Before we begin talking about how to install MariaDB on CentOS 8, let’s briefly understand – What is MariaDB?

MariaDB is a popular open-source relational database management system (RDBMS) that is widely used in web applications and enterprise environments. It is a robust and scalable alternative to MySQL, offering enhanced performance, high availability, and advanced features.

Developed by the original creators of MySQL, MariaDB provides seamless compatibility with MySQL, making it easy to migrate existing databases. Its user-friendly interface and extensive community support make MariaDB a top choice for businesses and developers seeking a reliable and efficient database solution.

In this tutorial, you will install MariaDB on CentOS 8. We will also address some FAQs related to the MariaDB installation.

Advantages of MariaDB

  1. Performance: MariaDB offers superior speed and performance, enabling faster query execution and data retrieval.
  2. High Availability: It ensures continuous availability of critical data through replication, clustering, and automatic failover mechanisms.
  3. Advanced Features: MariaDB provides advanced features like JSON support, GIS capabilities, and improved security options.
  4. Compatibility: It offers seamless compatibility with MySQL, making it easy to migrate existing MySQL databases to MariaDB.
  5. Community Support: MariaDB has a thriving and active community that provides support, regular updates, and additional plugins/extensions.

Prerequisites to Install MariaDB on CentOS 8

1) Remember to log in as a user with the sudo privileges.

Steps 1 – Installing MariaDB 10.3 on CentOS 8

1) The version of the MariaDB server in default CentOS repositories is version-10.3. It is not the latest version, but quite stable. Now, install the MariaDB package using the yum package manager:

sudo yum install mariadb-server

2) Next, press y after getting a prompt. It will enable you to proceed with the installation.

3) After installation is complete, start the MariaDB service and then enable it to start on boot using the below command:

sudo systemctl start mariadb
sudo systemctl enable mariadb

4) You will need to verify if the installation is successful. Also, check the MariaDB service status by:

sudo systemctl status mariadb

The output should show that the service is active and running as well.

5) Now, run the mysql_secure_installation script. It will perform several security-related tasks:

sudo mysql_secure_installation

6) You will get a prompt to set up the root user password. Next, remove any other anonymous user accounts. Also, restrict root-user access to the local machine. Moreover, remove the test database. It is a recommendation to answer Y (yes) to all questions.

Step 2 – Installing MariaDB 11.0 on CentOS 8

So there are two methods of installation

a) Using official script

b) Manual

A) Install MariaDB 11.0 using script

1) Execute the script using below command, here we are installing 11.0 version you can install any other by changing the value of --mariadb-server-version. See the supported versions by script here.

curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-11.0"

# [info] Checking for script prerequisites.
# [info] MariaDB Server version 11.0 is valid
# [info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
# [info] Adding trusted package signing keys...
/etc/pki/rpm-gpg /home/centos
# [info] Successfully added trusted package signing keys
# [info] Cleaning package cache...
34 files removed

2) After setting up the MariaDB Package Repository, you can install the software packages in the supported repositories.

sudo yum install MariaDB-server MariaDB-client MariaDB-backup -y

B) Manual

If you faced some issues with the script, you can always do with manual installation.

1) Here, the latest version of MariaDB is 11.0. If you want to install any other version of MariaDB, move over to the MariaDB repositories page. Further, generating a repository file for a specific MariaDB version.

First, you will enable the MariaDB repository. Create a repository file as MariaDB.repo. Next, add the below content:

sudo vi /etc/yum.repos.d/MariaDB.repo
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
baseurl = https://rpm.mariadb.org/11.0/centos/$releasever/$basearch
#baseurl = https://mirrors.aliyun.com/mariadb/yum/11.0/centos/$releasever/$basearch
gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
#gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

2) Install some dependencies

sudo yum install perl-DBI libaio libsepol lsof boost-program-options -y
sudo dnf install libpmem socat -y

2) Install the MariaDB server, as well as the client packages, using yum. Do the same as other CentOS packages:

sudo yum install --repo="mariadb" MariaDB-client MariaDB-server

3) Then yum may prompt you to import the MariaDB GPG key:


Importing GPG key 0x1BB943DB:
 Userid     : "MariaDB Package Signing Key <[email protected]>"
 Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB
 From       : https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
Is this ok [y/N]: y

Key imported successfully
Importing GPG key 0xC74CD1D8:
 Userid     : "MariaDB Signing Key <[email protected]>"
 Fingerprint: 177F 4010 FE56 CA33 3630 0305 F165 6F24 C74C D1D8
 From       : https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
Is this ok [y/N]: y

Type y and then pressEnter.

4) When the installation is complete. You will then enable MariaDB to start on boot. Next, start the service, by:

sudo systemctl enable mariadb
sudo systemctl start mariadb

5) To verify the installation, you will check the MariaDB service status by:

sudo systemctl status mariadb

● mariadb.service - MariaDB 11.0.2 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
   Active: active (running) since Wed 2023-07-26 09:50:55 UTC; 25min ago
     Docs: man:mariadbd(8)
  Process: 5736 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 5712 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_STA>
  Process: 5710 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 5722 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 9 (limit: 4403)
   Memory: 237.9M
   CGroup: /system.slice/mariadb.service
           └─5722 /usr/sbin/mariadbd

6) Now, run the mariadb-secure-installation script. It will perform several security related-tasks:

sudo mariadb-secure-installation
Note: From MariaDB.11.x the binary name is changed to mariadb from mysql, for more infomation check this out.

7) The script will again prompt you to set up the root user password. Then, remove the anonymous user and restrict root-user access to the local machine. As well as remove test-database. It is a recommendation to answer Y (yes) to all questions.

Step 3 – Connecting to the MariaDB from the command line

1) Now, to connect to the MariaDB server via the terminal as the root account, type:

mariadb -u root -p

2) You will get a prompt to enter the root password that was previously set. It was at the time mariadb-secure-installation script was run.


Enter password:

3) After you enter the password, you will be presented with the MariaDB shell as below:


Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 11.0.2-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)]>

FAQs to Install MariaDB on CentOS 8

What is the default port for MariaDB?

The TCP/IP port number is to use for the connection. The default port is 3306.

How to create a foreign key in the MariaDB?

You will need to specify the name of the foreign-key constraint after the constraint keyword. MariaDB will assign a generated name if you skip the constraint clause. Next, specify the name of the foreign key and a list of comma-separated column names. These need to be within the parentheses.

What is the default root password for MariaDB?

The default root password for MariaDB is Blank. By default, a MariaDB installation has an anonymous user which allows anyone to log into MariaDB. It is done without a need to have a user account made for them.

How many JOIN Clauses are Allowed in a Query?

The maximum number of tables that can be referenced in a single join is 61. This also applies to the number of tables that can be referenced in the definition of a view.

Where is the table_cache in MariaDB?

All versions of MariaDB are based on MySQL 5.1 and greater, thus the table_cache option is deprecated in favor of table_open_cache.

How do I create a new user in MariaDB?

Within the MariaDB shell, execute: CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';. Replace 'username' and 'password' accordingly.

How can I uninstall MariaDB from CentOS 8?

Run the following commands: sudo systemctl stop mariadb, sudo yum remove mariadb-server, and sudo rm -rf /var/lib/mysql/.


We hope this detailed guide helped you to install MariaDB on CentOS 8.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.