Installing the MariaDB database server on AlmaLinux 9 and 10

Linux 4 min read

MariaDB is an open-source database server that originated from MySQL and is largely compatible with it; WordPress and most PHP applications can use it without modification. This article explains how to install it on a VPS without a control panel; together with the web server, the installation of Apache and PHP-FPM as described in the relevant article forms a complete LAMP environment.

We tested these steps in October 2026 on AlmaLinux 9.8 and 10.2 systems. Run the commands as a user with sudo privileges.

1. Which version?

System Default Other versions are available in the system repository
AlmaLinux 10 MariaDB 10.11 MariaDB 11.8 (the mariadb11.8-server package)
AlmaLinux 9 MariaDB 10.5 MariaDB 10.11 and 11.8 as modules

On AlmaLinux 9, the default 10.5 branch is no longer supported by the MariaDB developers, so please select a module there. Both 10.11 and 11.8 are Long-Term Support (LTS) releases; for a new installation, 11.8 is the more recent version.

Selecting a module on AlmaLinux 9:

sudo dnf module enable mariadb:11.8

2. Installation and start-up

sudo dnf install mariadb-server
sudo systemctl enable --now mariadb

On AlmaLinux 10, the package name for version 11.8 is mariadb11.8-server. In the test on AlmaLinux 9, the mariadb-server-11.8.8 module was installed.

Check:

sudo mariadb -e "SELECT VERSION();"

3. The root user: a Unix socket instead of a password

Since version 10.4, the MariaDB root_user has been able to log in without a password, with root privileges: sudo mariadb works, but when running mariadb -u root as a standard user, it returns the following:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

This is both secure and convenient: you do not need to store a password for the database’s root account, and it cannot be accessed from outside. Do not set a password for it simply so that an application can connect as root; create a separate user for applications (see point 5).

4. Basic security settings

sudo mariadb-secure-installation

(The old name mysql_secure_installation also works.) We answered the script’s questions as follows during the test:

Question Suggested answer
Enter your current root password Enter (no password required)
Switch to unix_socket authentication n (this is already how it works)
Change the root password? n
Remove anonymous users? Y
Disallow remote root login? Y
Remove the test database and access to it? Y
Reload privilege tables now? Y

The message All done! will appear at the end.

5. Creating a database and a user

Create a separate database and user for each application (for example, each WordPress site), with permissions restricted to that specific database only:

sudo mariadb
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'Hosszu-Egyedi-Jelszo';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Testing with a new user:

mariadb -u wpuser -p -e "SELECT CURRENT_USER(); SHOW DATABASES;"

During the test, the user could only see the information_schema and their own wordpress database.

6. Do not make it accessible from outside

In the test, following the installation of MariaDB, it was listening on all network interfaces (ss -tlnp shows 0.0.0.0:3306), meaning it would have been possible to access it from the internet without a firewall. If the database is only used by an application running on the same server (which is typically the case), restrict access to the local address. In the /etc/my.cnf.d/mariadb-server.cnf file, within the [mysqld] section:

bind-address = 127.0.0.1
sudo systemctl restart mariadb
sudo ss -tlnp | grep 3306

After the test, only 127.0.0.1:3306 remained. If firewalld is running on the server, do not open port 3306; instead, use an SSH tunnel for remote access.

7. Memory

The size of the InnoDB buffer pool (innodb_buffer_pool_size) is set to 128 MB by default. If your database is larger and there is free memory on the server, increase this value in the /etc/my.cnf.d/mariadb-server.cnf file under the [mysqld] section (for example, innodb_buffer_pool_size = 512M). If the web server is also running on the same machine, allocate no more than 40–50 per cent of the total memory to it; otherwise, the OOM killer may shut down the database (see: Out of memory: OOM killer and swap file).

Backup

sudo mariadb-dump --single-transaction wordpress > wordpress-$(date +%F).sql

For more information on backups and restores, see the article ‘How to back up and restore data on a Linux system?’.

Useful commands

Command What does it do?
sudo systemctl status mariadb Is the service running?
sudo systemctl restart mariadb Restart (e.g. after changing settings)
sudo journalctl -u mariadb Service log
sudo mariadb Log in as root
mariadb -u felhasznalo -p adatbazis Logging in with an application user

If you do not wish to run a database server, you can create databases via the interface on cPanel hosting plans (see: Creating MySQL databases and users on cPanel hosting), or install them on your own KVM VPS using the steps above.

Back: Linux articles (62)