MariaDB is a community-developed, fully open-source relational database management system that was forked from MySQL and remains highly compatible with it. On RHEL 8, MariaDB is conveniently available through the AppStream module system, allowing you to install a specific stream version without adding third-party repositories. This tutorial covers installing MariaDB 10.5 via AppStream, starting and enabling the service, running the security script, creating a database and user, and opening the firewall for remote connections. You will also learn where MariaDB stores its configuration so you can tune it for your workload.
Prerequisites
- A server running RHEL 8 or a compatible derivative (AlmaLinux 8, Rocky Linux 8)
- Root or
sudoaccess to the system dnfand a working internet connection to reach RHEL AppStream repositoriesfirewalldactive if remote database access is required
Step 1 — Install MariaDB via the AppStream Module
RHEL 8 ships MariaDB as an AppStream module with multiple available streams. The 10.5 stream is a solid long-term-support choice that includes performance and security improvements over earlier versions. Install the server profile of the mariadb:10.5 module with a single command:
sudo dnf module install -y mariadb:10.5/server
To see all available MariaDB streams before installing, run:
dnf module list mariadb
If you require a newer version such as 10.6 or 10.11, you can add the official MariaDB repository instead. Create the file /etc/yum.repos.d/mariadb.repo with the content provided at mariadb.org for your target version, then run sudo dnf install -y MariaDB-server.
Step 2 — Start and Enable the MariaDB Service
After installation, enable the mariadb systemd service so it starts on every boot, then start it immediately:
sudo systemctl enable --now mariadb
Confirm the service is running:
sudo systemctl status mariadb
The output should show active (running). MariaDB listens on TCP port 3306 by default.
Step 3 — Secure the MariaDB Installation
Fresh MariaDB installations have no root password and include anonymous accounts and a test database. Run the included security script to remove these defaults and set a strong root password:
sudo mysql_secure_installation
Follow the interactive prompts: press Enter for the current root password (blank by default), then answer Y to set a new root password and to all subsequent hardening questions. The script will remove anonymous users, disallow remote root login, remove the test database, and reload privilege tables.
Step 4 — Create a Database and User
Log in to MariaDB as root and create an application database along with a dedicated user that has full privileges on that database only:
sudo mysql -u root -p
At the MariaDB prompt, run the following SQL statements, substituting your chosen values for appdb, appuser, your_host, and StrongPassword1!:
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'your_host' IDENTIFIED BY 'StrongPassword1!';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'your_host';
FLUSH PRIVILEGES;
EXIT;
Use localhost as the host value if the application runs on the same server, or the application server’s IP address for a remote connection.
Step 5 — Configure the Firewall for Remote Access
If your application server is on a different host, open the MySQL/MariaDB service port in firewalld:
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
For tighter security, restrict access to a specific source IP rather than opening the port globally:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.50" service name="mysql" accept'
sudo firewall-cmd --reload
Step 6 — Tune MariaDB via the Configuration Directory
MariaDB on RHEL 8 reads configuration snippets from /etc/my.cnf.d/. Rather than editing the main /etc/my.cnf file, create a custom override file in that directory. Common tuning parameters include the InnoDB buffer pool size, query cache settings, and the maximum number of connections:
sudo tee /etc/my.cnf.d/custom.cnf <<'EOF'
[mysqld]
innodb_buffer_pool_size = 256M
max_connections = 150
slow_query_log = 1
slow_query_log_file = /var/log/mariadb/slow-queries.log
long_query_time = 2
EOF
sudo systemctl restart mariadb
Adjust innodb_buffer_pool_size to approximately 70–80% of available RAM for a dedicated database server.
Conclusion
You have installed MariaDB 10.5 on RHEL 8 using the AppStream module system, secured the installation, created an application database and user, configured the firewall, and applied basic performance tuning. MariaDB is now ready to serve your applications with a production-grade configuration.
Next steps: How to Configure MariaDB Replication on RHEL 8, How to Back Up and Restore MariaDB Databases with mariabackup, and How to Enable SSL/TLS for MariaDB Connections on RHEL 8.