How to install MariaDB on AlmaLinux 9
Installing MariaDB on AlmaLinux 9 takes just a few minutes. This guide walks you through the process, step by step:
-
Update AlmaLinux 9
-
Set up the repository
-
Install and start MariaDB
-
Secure the installation
-
Create a database and user account
Why combine MariaDB with AlmaLinux 9?
MariaDB is a widely used, high-performance open-source database. It is based on MySQL but includes additional features and is trusted in many enterprise environments. AlmaLinux 9 is a free, binary-compatible alternative to RHEL. Together, they are an excellent option for developers, small businesses and administrators looking for a stable, secure, license-free server platform.
What requirements does my setup need to meet?
Before you begin, make sure your setup meets the following requirements:
- A system with AlmaLinux 9 pre-installed
- Root access or a user account with sudo privileges
- Internet connection for package downloads
- Terminal access via console or SSH
- Cost-effective vCPUs and powerful dedicated cores
- Flexibility 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 distribution, such as RHEL or Ubuntu 24.04, we recommend looking at our other tutorials.
Step 1: Update the system
Before installing 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 -ybashThis command updates all installed packages to the latest version. If the kernel or core components are updated, restart the system:
sudo rebootbashStep 2: Set up the MariaDB repository
The MariaDB version included in the default AlmaLinux repositories may be outdated. To install the current stable release, configure the official AlmaLinux 9 MariaDB repository.
Create a new file:
sudo vi /etc/yum.repos.d/mariadb.repobashInsert 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 = 1bashSave the file and close with :wq. Then refresh the package sources so that the new repository is taken into account:
sudo dnf clean all
sudo dnf makecachebashThis ensures the package manager uses the latest information from the MariaDB repository.
Step 3: Install MariaDB
Now install the database server with:
sudo dnf install mariadb-server -ybashThe system will download and install all required packages. The -y flag automatically confirms prompts in advance.
- Enterprise-grade architecture managed by experts
- Flexible solutions tailored to your requirements
- Leading security in ISO-certified data centers
Step 4: Start and enable the service
After the installation is complete, start the MariaDB service:
sudo systemctl start mariadbbashEnable it to start automatically at system startup:
sudo systemctl enable mariadbbashCheck its status:
sudo systemctl status mariadbbashThe service should now be active and running. If so, you can move on to the configuration.
<box-note>
If SELinux is enabled (default in AlmaLinux 9), it might block external database connections. 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_installationbashYou 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 privileges: Yes
These steps strengthen the security of your installation.
Step 6: Create a user and database
Next, create a database and a user account with the required privileges. To do this, first log in to the AlmaLinux 9 MariaDB console:
sudo mariadb -u root -pbashEnter the root password you set earlier. You should then see the MariaDB prompt:
MariaDB [(none)]>sqlCreate a new database, for example:
CREATE DATABASE db_name;sqlThen, create a new user and set a secure password:
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'safepassword';sqlGrant this user full privileges on the database you created earlier:
GRANT ALL PRIVILEGES ON db_name.* TO 'dbuser'@'localhost';sqlFinally, reload the privileges:
FLUSH PRIVILEGES;sqlExit the MariaDB console:
EXIT;sql
