How to Install MariaDB on Rocky Linux 8

MariaDB is an open-source RDBMS that is mostly used for web development. It uses MySQL as its primary storage engine, but it is also lightweight, secure, and features in-memory ACID transactions. MariaDB was originally created by Michael Howard, a former engineer from Oracle Corporation and the Vice President of Engineering at Sun Microsystems. While it was initially developed as an alternative to a proprietary database, like MySQL or PostgreSQL, MariaDB has since become one of the most popular open-source databases on the market due to its high performance in large-scale deployments with hundreds of concurrent connections and its ease of use for developers.

MariaDB was created on January 9, 2002, when it was released as version 0.54 of the MySQL Community Server. It has since matured into a database that is used in high-traffic websites like Facebook and Wikipedia. Since then, MariaDB has been embraced by the open-source community and is now maintained by the MariaDB Foundation under the leadership of Michael Howard.

An important feature of MariaDB is that it does not use SQL queries to store data in memory; instead, it stores rows of data as flat files that can be managed by additional administrative tools needed to manage multiple databases on a single machine.

The MariaDB project does not disclose the number of databases that are hosted on the open-source version of MariaDB. However, according to the August 1st, 2008 estimate from MySQL.com, there are approximately one million active installations of MariaDB. In addition to this, the number of MariaDB developers has grown from one hundred in 2002 to sixteen thousand in 2009.

While many modern web applications use MySQL as a storage engine, it is often used in conjunction with MariaDB for reasons including performance and easy administration.

MariaDB is popular among web developers because it provides an easy interface for many common tasks related to MySQL that require configuration files and SQL queries.

You have a website or a service that requires MariaDB. But you do not have MariaDB installed on your machine. How do you install it on your server? This guide will walk you through the process. When you complete this tutorial, you will have a fully functional MariaDB server on your Rocky Linux 8 server.

Let’s get started!

Prerequisites

In order to complete this tutorial, you will need an Ubuntu Server that has the following prerequisites:

  • This tutorial will require root access to install MariaDB.
  • A Rocky Linux 8 server with at least 2GB of memory to run MariaDB.

Updating Your System

The first step is to update your system to the latest version of the package list. To do so, run the following commands.

sudo dnf check-update && sudo dnf update -y

Sample output:

Update the system

Adding Repository for MariaDB

Now that your system is up-to-date, the next step is to add the repository for MariaDB. By default, the base repository of Rocky Linux 8 comes with the version 10.3 of MariaDB, which is somewhat old compared to its versions today.

Run the sudo dnf module list mariadb command to see the version of MariaDB modules in your system.

sudo dnf module list mariadb

You will get an output list this:

dnf list

Run the sudo nano /etc/yum.repos.d/mariadb.repo command to create a MariaDB repository file named mariadb.repo in the yum.repos.d directory.

sudo nano /etc/yum.repos.d/mariadb.repo

Repository files are used to download software packages (applications, libraries, etc.) from a server that is maintained by a third-party. In this case, it’s the MariaDB developer. A repository file contains information about a particular repository and the software associated with it.

A repository file is used to specify the location of a particular software package and the version of that package. The repo you are creating in this tutorial has one line that specifies the name of your MariaDB server and its version.

Paste the following content into it and save it using the CTRL+O command and the CTRL+X command to exit the nano text editor.

# MariaDB 10.6 RedHat repository list - created UTC
# https://mariadb.org/download/

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

Where:

  • [mariadb] is to create a new repository section
  • ‘name’ is the repo name, which should be unique
  • ‘baseurl’ specifies where to find the packages. The ‘curly brackets’ are to be replaced with actual values.
  • ‘module_hotfixes=1’ is to ensure the GPG key is enabled
  • ‘gpgkey’ points to the key that allows secure packages download
  • ‘gpgcheck=1’ is to ensure the packages are validated by GPG.

You can generate your own lines for your repo file by using the MariaDB Package Repository Setup tool here.

MariaDB repository

At this time of writing, MariaDB 10.6 is the latest stable release. We will use this stable release as an example. There is a MariaDB 10.7 RC in release, but this is an unstable release. We will not use the RC in our example here.

MariaDB 10.7 is a Release Candidate(RC), meaning it’s a preview of what will be the next stable release. This allows us to test the upcoming stable release and get it ready for production.

Rerun the sudo dnf update -y command to update your package list.

sudo dnf update -y

Run the sudo dnf repolist command to display your MariaDB repository.

sudo dnf repolist

You will see your MariaDB repository added to your package list.

dnf repolist

Run the sudo dnf repolist mariadb

command to check if the MariaDB 10.6 YUM repository is enabled.

sudo dnf repolist mariadb

You will see that your MariaDB 10.6 YUM repository is enabled.

MariaDB repository has been enabled

If not, run the sudo dnf module enable mariadb:10.6 command to enable the 10.6 version of MariaDB.

sudo dnf module enable mariadb:10.6

Install MariaDB on Rocky Linux 8

Now that your repository is set up, you can install MariaDB.

Run the sudo dnf install mariadb-server mariadb -y command to install MariaDB server and client packages.

sudo dnf install mariadb-server mariadb -y

Sample output:

Install MariaDB server

Once the installation process completes, run the mariadb-secure-installation script to secure your MariaDB installation.

MariaDB provides what is called a “root user”. The root user has full access to MariaDB. This means, if there are any security vulnerabilities in MariaDB, the damage can be significant.

We should secure our installation by changing the root password, removing anonymous user accounts, and disabling remote root logins.

The mariadb-secure-installation script performs security checks and prompts us for needed actions. This reduces the possibility of operating system and MariaDB misconfiguration.

The mariadb-secure-installation script can help us secure a MariaDB installation. Specifically, this allows us to:

  • Set a root password
  • Remove anonymous user accounts and disable remote root logins
  • Remove test database, access and error logs
  • Reload privilege tables to effect changes made to the grant tables
mariadb-secure-installation

You will be asked to enter the password for the MariaDB root user. Press Enter to proceed since this is the first time you install MariaDB.

Secure MariaDB installation

You will then be asked if you want to Switch to unix_socket . Click Y to continue.

Unix_socket authentication is a security authentication method that allows the client to connect to the MariaDB server directly, without going through the operating system. This can improve security because clients connecting through Unix sockets are authenticated by the server itself, rather than by the operating system.

Unix socket authentication

You will then be asked if you want to** Change the root password**. Type Y and press Enter. Provide a secure password and press Enter.

Change root password

For the remaining steps, you can type Y and press Enter to all the questions.

Securing MariaDB

Testing the MariaDB installation

Now that MariaDB is installed, you can test the connection to your MariaDB server. This step will allow you to test how your MariaDB installation is performing and make any necessary adjustments prior to moving your database to a full production environment.

Run the sudo mysql -u root -p command to log in to the MariaDB shell. The MariaDB shell is a command-line interface that you can use to interact with the MariaDB server. For example, you can run the SHOW TABLES, SHOW VARIABLES, and SELECT commands.

sudo mysql -u root -p
  • mysql is the name of the command you are using to connect to the MariaDB server.
  • -u root tells MariaDB that you want to log in as the root user.
  • -p ensures that you are prompted to enter your password before the MariaDB shell will connect.

After you initiate the connection, MariaDB will ask you for your MariaDB root password. Type in the password you set earlier and press Enter.

You should now see the MariaDB shell, as shown below.

Connect to MariaDB

Run the sudo mysqladmin version command for double-checking your MariaDB version. Note that the version number may differ from what is shown in the screenshot below. mysqladmin is a MariaDB tool used to administer the server. The version command will return the current version of the MariaDB server.

sudo mysqladmin version

You will get the following output.

Check mariaDB version

Finally, run the systemctl status mariadb command to view your MariaDB service status.

sudo systemctl status mariadb

You will get the following output. This output shows that the MariaDB service is currently up and running.

Check database status with systemctl command

Conclusion

MariaDB is a powerful, popular, and highly scalable relational database. It is a very flexible open-source alternative to proprietary databases such as Oracle and Microsoft SQL Server.

In this guide, we have discussed how to install and secure MariaDB 10.6 on Rocky Linux 8 Linux distribution. You have also been introduced to some of the most essential commands for MariaDB management.