In­stalling MariaDB on AlmaLinux 9 takes just a few minutes. This guide walks you through the process, step by step:

  1. Update AlmaLinux 9

  2. Set up the re­pos­it­ory

  3. Install and start MariaDB

  4. Secure the in­stall­a­tion

  5. Create a database and user account

Why combine MariaDB with AlmaLinux 9?

MariaDB is a widely used, high-per­form­ance open-source database. It is based on MySQL but includes ad­di­tion­al features and is trusted in many en­ter­prise en­vir­on­ments. AlmaLinux 9 is a free, binary-com­pat­ible al­tern­at­ive to RHEL. Together, they are an excellent option for de­velopers, small busi­nesses and ad­min­is­trat­ors looking for a stable, secure, license-free server platform.

What re­quire­ments does my setup need to meet?

Before you begin, make sure your setup meets the following re­quire­ments:

  • A system with AlmaLinux 9 pre-installed
  • Root access or a user account with sudo priv­ileges
  • Internet con­nec­tion for package downloads
  • Terminal access via console or SSH
Compute Engine
The ideal IaaS for your workload
  • Cost-effective vCPUs and powerful dedicated cores
  • Flex­ib­il­ity with no minimum contract
  • 24/7 expert support included

How to install MariaDB on AlmaLinux 9

Here’s how to install MariaDB on AlmaLinux 9step by step. If you want to run MariaDB on a different dis­tri­bu­tion, such as RHEL or Ubuntu 24.04, we recommend looking at our other tutorials.

Step 1: Update the system

Before in­stalling new software, always make sure your system is up to date. This helps prevent version conflicts and strengthens security.

Open a terminal and run the following:

sudo dnf update -y
bash

This command updates all installed packages to the latest version. If the kernel or core com­pon­ents are updated, restart the system:

sudo reboot
bash

Step 2: Set up the MariaDB re­pos­it­ory

The MariaDB version included in the default AlmaLinux re­pos­it­or­ies might be outdated. To install the current stable release, configure the official AlmaLinux 9 MariaDB re­pos­it­ory.

Create a new file:

sudo vi /etc/yum.repos.d/mariadb.repo
bash

Insert the following content:

# MariaDB 11.7 AlmaLinux 9 Repository
[mariadb]
name = MariaDB
baseurl = https://mirror.23m.com/mariadb/yum/11.7/almalinux/$releasever/$basearch
module_hotfixes = 1
gpgkey = https://mirror.23m.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
bash

Save the file and close with :wq. Then refresh the package sources so that the new re­pos­it­ory is taken into account:

sudo dnf clean all
sudo dnf makecache
bash

This ensures the package manager uses the latest in­form­a­tion from the MariaDB re­pos­it­ory.

Step 3: Install MariaDB

Now install the database server with:

sudo dnf install mariadb-server -y
bash

The system will download and install all required packages. The -y flag auto­mat­ic­ally confirms prompts in advance.

Step 4: Start and enable the service

After the in­stall­a­tion is complete, start the MariaDB service:

sudo systemctl start mariadb
bash

Enable it so that it starts auto­mat­ic­ally when the system boots:

sudo systemctl enable mariadb
bash

Check its status:

sudo systemctl status mariadb
bash

The service should now be active and running. If so, you can move on to the con­fig­ur­a­tion.

<box-note>

If SELinux is enabled (default in AlmaLinux 9), it might block external database con­nec­tions. Allow network access by using the command sudo setsebool -P mysqld_can_network_connect 1. If you use your own data directory, set the correct context with sudo semanage fcontext -a -t mysqld_db_t “/data/mysql(/.*)?”. Then apply the rule with sudo restorecon -Rv /data/mysql.

</box-note>

Step 5: Secure MariaDB

MariaDB provides a built-in security setup script. To run it, use:

sudo mariadb_secure_installation
bash

You will then be asked whether you want to:

  • Set a root password (if not already set)
  • Remove anonymous users: Yes
  • Disable root login over the network: Yes
  • Delete the test database: Yes
  • Reload priv­ileges: Yes

These steps strengthen the security of your in­stall­a­tion.

Step 6: Create a user and database

Next, create a database and a user account with the required priv­ileges. To do this, first log in to the AlmaLinux 9 MariaDB console:

sudo mariadb -u root -p
bash

Enter the root password you set earlier. You should then see the MariaDB prompt:

MariaDB [(none)]>
sql

Create a new database, for example:

CREATE DATABASE db_name;
sql

Then, create a new user and set a secure password:

CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'safepassword';
sql

Grant this user full priv­ileges on the database you created earlier:

GRANT ALL PRIVILEGES ON db_name.* TO 'dbuser'@'localhost';
sql

Finally, reload the priv­ileges:

FLUSH PRIVILEGES;
sql

Exit the MariaDB console:

EXIT;
sql
Go to Main Menu