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.
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.
You can check the version of MariaDB installed as follows.
$ 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
It’s also prudent to set the daemon to start on system startup.
$ sudo systemctl enable mariadb
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.
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.
Then provide the password for the root account and confirm it.
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.
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
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 [email protected] IDENTIFIED BY "secure_password";
Next, grant privileges to the database user on the database.
MariaDB [(none)]> GRANT ALL ON linuxshelltips_db.* TO [email protected];
Flush privileges and exit the MariaDB console.
MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> exit
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;
You might also like to read the following related articles on MySQL:
- MySQL Database Commands Cheat Sheet for Linux
- How to Check MySQL User Privileges in Linux
- How to Rename MySQL Database Name in Linux
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.