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 repos­i­to­ry

  3. Install and start MariaDB

  4. Secure the in­stal­la­tion

  5. Create a database and user account

Why combine MariaDB with AlmaLinux 9?

MariaDB is a widely used, high-per­for­mance open-source database. It is based on MySQL but includes ad­di­tion­al features and is trusted in many en­ter­prise en­vi­ron­ments. AlmaLinux 9 is a free, binary-com­pat­i­ble al­ter­na­tive to RHEL. Together, they are an excellent option for de­vel­op­ers, small busi­ness­es and ad­min­is­tra­tors 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­i­leges
  • 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­i­bil­i­ty 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­b­u­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 strength­ens 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­po­nents are updated, restart the system:

sudo reboot
bash

Step 2: Set up the MariaDB repos­i­to­ry

The MariaDB version included in the default AlmaLinux repos­i­to­ries may be outdated. To install the current stable release, configure the official AlmaLinux 9 MariaDB repos­i­to­ry.

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 repos­i­to­ry is taken into account:

sudo dnf clean all
sudo dnf makecache
bash

This ensures the package manager uses the latest in­for­ma­tion from the MariaDB repos­i­to­ry.

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 au­to­mat­i­cal­ly confirms prompts in advance.

Managed Databases
Time-saving database services
  • En­ter­prise-grade ar­chi­tec­ture managed by experts
  • Flexible solutions tailored to your re­quire­ments
  • Leading security in ISO-certified data centers

Step 4: Start and enable the service

After the in­stal­la­tion is complete, start the MariaDB service:

sudo systemctl start mariadb
bash

Enable it to start au­to­mat­i­cal­ly at system startup:

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­u­ra­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 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­i­leges: Yes

These steps strength­en the security of your in­stal­la­tion.

Step 6: Create a user and database

Next, create a database and a user account with the required priv­i­leges. 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­i­leges on the database you created earlier:

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

Finally, reload the priv­i­leges:

FLUSH PRIVILEGES;
sql

Exit the MariaDB console:

EXIT;
sql
Go to Main Menu