Home MongoDB How to Install MariaDB Server in RHEL 9 Linux

How to Install MariaDB Server in RHEL 9 Linux

MariaDB is a free and open-source Relational Database Management System (RDBMS) that is a fork of MySQL. It’s a widely used database server and a household name among developer circles. From novices to intermediate and advanced database administrators, MariaDB has stamped its authority as one of the leading SQL databases in the industry.

In this guide, we will demonstrate how to install MariaDB on RHEL 9. We will install the community version which is free to download and use.

Step 1: Enable RedHat Subscription in RHEL 9

To kickstart the installation, ensure that you have an instance of RHEL 9 with an active RHSM subscription. To check if your system has a subscription, run the command:

$ sudo subscription-manager list --installed

If your system has a subscription, you should get the following output.

Check RHEL Subscription
Check RHEL Subscription

Otherwise, enable subscription by running the following command:

$ subscription-manager register --username=username --password=password--auto-attach

Where the username and password credentials are the login details to your Red Hat account.

Next, upgrade all the packages on your system by running the following command:

$ sudo dnf update -y

Step 2: Install MariaDB on RHEL 9

MariaDB server package alongside other dependencies is already provided by RHEL 9 AppStream repositories. Currently, the version offered is MariaDB 10.5.

Therefore, use the DNF package manager to install the MariaDB server as follows:

$ sudo dnf install mariadb-server -y

The command installs MariaDB alongside other MariaDB dependencies and Perl packages.

Install MariaDB in RHEL 9
Install MariaDB in RHEL 9

You can check the version of MariaDB installed as follows.

$ mariadb --version
Check MariaDB Version
Check MariaDB Version

The MariaDB daemon does not automatically start once installed. It’s for this reason that we need to start the service. To do so, run the command:

$ sudo systemctl start mariadb

You can then verify the status of the MariaDB daemon.

$ sudo systemctl status mariadb
Check MariaDB Status
Check MariaDB Status

It’s also prudent to set the daemon to start on system startup.

$ sudo systemctl enable mariadb
Start MariaDB on Boot
Start MariaDB on Boot

To log into the MariaDB database server, run the command:

$ sudo mariadb

This drops you to the MariaDB shell prompt. Just above the prompt, you find details such as the connection ID and server version.

Login to MariaDB
Login to MariaDB

Step 3: Secure MariaDB on RHEL 9

MariaDB, just like MySQL is not secure by default. Therefore, you need to take an additional step and run the mysql_secure_installation script.

$ sudo mysql_secure_installation

Running the command walks you through a series of prompts. Firstly, you will be required to set a root password. From MariaDB 10.4, the root user uses unix_socket authentication by default which is not secure enough.

So, decline from using the unix_socket authentication by pressing n and hitting ENTER.

MariaDB Unix Socket Authentication
MariaDB Unix Socket Authentication

Then provide the password for the root account and confirm it.

Set MariaDB Root Password
Set MariaDB Root Password

For the remaining prompts, type ‘Y’ to remove anonymous users, disallow remote root login and remove the test database and access to it, and finally reload the privilege tables.

Secure MariaDB Server
Secure MariaDB Server

At this point, you have successfully secured MariaDB to the required basic standards.

Let us now log in and create a database and database user.

Step 4: Create MariaDB Database on RHEL 9

Now, login back to the MariaDB server and authenticate with the password you configured.

$ sudo mariadb -u root -p
Login to MariaDB
Login to MariaDB

Create a test database. Here, we are going to name it linuxshelltips_db.

MariaDB [(none)]> CREATE DATABASE linuxshelltips_db;

Next, create a database user. Replace secure_password with your own strong password.

MariaDB [(none)]> CREATE USER linuxshelltips_user@localhost IDENTIFIED BY "secure_password";

Next, grant privileges to the database user on the database.

MariaDB [(none)]> GRANT ALL ON linuxshelltips_db.* TO linuxshelltips_user@localhost;

Flush privileges and exit the MariaDB console.

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit 
Create MariaDB Database
Create MariaDB Database

To list all the databases, run the command:

MariaDB [(none)]> SHOW DATABASES;

To list all the users created, execute:

MariaDB [(none)]> SELECT User FROM mysql.user;
List MariaDB Database
List MariaDB Database

You might also like to read the following related articles on MySQL:

This article has demonstrated how to install the MariaDB database server on RHEL 9. We have further demonstrated how to secure the database server and how to run queries to create a test database and database user.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.