Skip to content

How to install and configure MariaDB in CentOS / RHEL 7?

Updated 1 min read

Updated: 28 September 2026 · Applies to: AlmaLinux 9 / Rocky Linux 9 and Ubuntu 24.04

CentOS 7 reached end of life on 30 June 2024, so this guide now uses AlmaLinux 9 / Rocky Linux 9 (the steps also suit other RHEL 9 rebuilds).

MariaDB is a drop-in replacement for MySQL and the default database server on most Linux distributions.

Install from the distribution

dnf install mariadb-server
systemctl enable --now mariadb
mariadb-secure-installation

AlmaLinux/Rocky 9 include MariaDB 10.5. On Ubuntu 24.04 and Debian 12: apt install mariadb-server (MariaDB 10.11).

Install a newer version from MariaDB's repository

curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash -s -- --mariadb-server-version=11.4
dnf install MariaDB-server     # apt install mariadb-server on Ubuntu/Debian
systemctl enable --now mariadb

Basic configuration

Settings go in /etc/my.cnf.d/ (AlmaLinux/Rocky) or /etc/mysql/mariadb.conf.d/ (Ubuntu/Debian). A common starting point on a server with 4 GB RAM:

[mysqld]
innodb_buffer_pool_size = 1G
max_connections = 150
bind-address = 127.0.0.1

Restart with systemctl restart mariadb. Keep bind-address = 127.0.0.1 unless other servers must connect.

Create a database

mariadb -u root -p
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'Strong-Password';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

War diese Antwort hilfreich?

Still stuck? Open a ticket