How to Install MariaDB on Rocky Linux and AlmaLinux

MariaDB is a free and community-developed relational database system that is a compatible drop-in replacement for the hugely popular MySQL database management system.

It was forked from MySQL after the original developers of MySQL expressed their misgivings with the acquisition of MySQL by Oracle. Since then, MariaDB is guaranteed to remain free and open source under the GNU license.

MariaDB is massively popular for its fast performance, scalability, stability, and robustness. It is compatible with a wide range of operating systems including Linux, FreeBSD, Mac, and Windows.

The rich set of storage engines, plugins, and other cool tools that it provides make it an ideal option for various use cases such as data analytics, data warehousing, transactional processing, and so on. In fact, it’s a key component of the LAMP & LEMP stacks which are used for hosting web applications.

MariaDB Features

Key Features of MariaDB include:

  • Galera clustering technology.
  • New Storage engines such as InnoDB, XtraDB, Aria, TokuDB, CONNECT, and SEQUENCE to mention a few.
  • Faster and improved replication.
  • Advanced thread pool capable of supporting up to 200,00+ connections.
  • New features such as system-versioned tables, anchored data types, and UNIX socket authentication to mention a few.

In this article, we walk you through how to install the MariaDB database server on Rocky Linux 8 and AlmaLinux 8.

Step 1: Add MariaDB Repository in Rocky Linux

By default, the Rocky Linux AppStream repository provides MariaDB 10.3. However, this is not the latest version. At the moment, the current stable release is MariaDB 10.6.

To install the latest version, create a MariaDB repository file on your system as follows.

$ sudo vim /etc/yum.repos.d/mariadb.repo

Paste the lines shown.

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.6/rhel8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1 

Then save the changes and exit from the file.

Next, update the system repositories for Rocky to register the newly added repository.

$ sudo dnf update

Step 2: Install MariaDB in Rocky Linux

With the repository in place, move along and install the MariaDB database server as shown:

$ sudo dnf install mariadb-server mariadb

Once installed, enable MariaDB service to start on boot time and start the service using the following commands.

$ sudo systemctl enable mariadb
$ sudo systemctl start mariadb

Then verify the running status of MariaDB.

$ sudo systemctl status mariadb

The output shows that everything is working as it should.

Check MariaDB Status
Check MariaDB Status

Step 3: Secure MariaDB in Rocky Linux

MariaDB comes with default settings that are weak and present security risks that can cause the database server to be exploited by hackers. Therefore, we need to take additional measures to secure the database server.

To do so, we will run the script below.

$ sudo mysql_secure_installation

First, set the root password.

Set MariaDB Root Password
Set MariaDB Root Password

For the remaining prompts, press ‘Y’ to purge anonymous users, disallow remote root login and remove the test database which is not required in production and finally save the changes.

Secure MariaDB Installation
Secure MariaDB Installation

To log in to the MariaDB database server, run the following command

$ sudo mysql -u root -p

Provide the root password that you configured in the previous step and press ENTER to access the MariaDB shell.

Login to MariaDB Shell
Login to MariaDB Shell

And there you go. We have successfully installed the MariaDB database server on Rocky Linux 8. Remember, you can still use the version provided by the AppStream repository which will work just fine. However, if you are looking to install the latest version of MariaDB, then adding the repository will do the trick.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.