Jun 9, 2023 5 min read

How to Install MariaDB on CentOS 7

Install MariaDB on CentOS 7 with our step-by-step tutorial. It is a widely-used open-source RDBMS in web applications and enterprises.

Install MariaDB on CentOS 7
Table of Contents

Choose a different version or distribution


Before we begin talking about how to install MariaDB on CentOS 7, 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 7. 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 7

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

Steps 1 – Installing MariaDB 5.5 on CentOS 7

1) The version of the MariaDB server in default CentOS repositories is version-5.5. 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 10.3 on CentOS 7

1) Here the latest version of MariaDB is 10.3. 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:

# MariaDB 10.3 CentOS repository list - created 2018-05-25 19:02 UTC
# http://downloads.mariadb.org/mariadb/repositories/
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64

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

sudo yum install MariaDB-server MariaDB-client

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


Retrieving key from https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Importing GPG key 0x1BB943DB:
 Userid     : "MariaDB Package Signing Key <[email protected]>"
 Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db
 From       : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

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 10.3.7 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
   Active: inactive (dead)
     Docs: man:mysqld(8)

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

sudo mysql_secure_installation

7) The script will again prompt 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 MariaDB server via terminal as the root-account, type:

mysql -u root -p

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

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 8
Server version: 10.3.7-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.

FAQs to Install MariaDB on CentOS 7

What is the default port for the MariaDB?

The TCP/IP port number is to use for the connection. The default is 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 the 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 7?

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 7.

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.