Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Install on Ubuntu and Debian

sudo apt update
sudo apt install mariadb-server

This installs the MariaDB server and the mariadb client from the distribution's own repositories. The service starts by itself and is enabled at boot. On Debian, MariaDB is the default MySQL-compatible server; Debian 12 and 13 have no mysql-server package. On Ubuntu both are available, but the two server packages conflict, so install one of them, not both. For MySQL instead, see how to install MySQL on Ubuntu.

Install on AlmaLinux and Rocky Linux

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

On the RHEL family the service is not started after installation, so the second command starts it and enables it at boot. To see which version the repositories offer before you install, run dnf info mariadb-server. The AppStream repository also carries MySQL (mysql-server on version 9, mysql8.4-server on version 10); choose one of the two.

Check the Service and the Version

sudo systemctl status mariadb
mariadb --version
sudo mariadb -e "SELECT VERSION();"

The first command should show the service as active. The second shows the client version and the third the running server, whose version string contains the word MariaDB. More ways to read it are in how to check the MySQL version. If the service is not active, read its messages with sudo journalctl -u mariadb.

Run the Security Script

sudo mariadb-secure-installation

The script's older name is mysql_secure_installation; on Debian 13 and Ubuntu 26.04 that old name comes only with the mariadb-client-compat package. It asks a series of questions:

  • Current root password: press Enter. Root has no password; it logs in through the socket.
  • Switch to unix_socket authentication: if the script reports that root is already protected this way, answer no; nothing changes.
  • Change the root password: answer no and keep socket login.
  • Remove anonymous users: yes.
  • Disallow root login remotely: yes.
  • Remove the test database: yes.
  • Reload privilege tables: yes, so the changes apply at once.

How root Logs In

sudo mariadb

No password is asked. MariaDB's root account uses the unix_socket plugin by default: the server checks that the Linux user running the client is root. Only users with sudo rights get in, which is safer than a password that can be guessed. To see how the account is defined:

SHOW CREATE USER 'root'@'localhost';

Use root for administration only. Applications get their own accounts.

Create a Database and an Application User

Inside sudo mariadb:

CREATE DATABASE app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON app.* TO 'app_user'@'localhost';

Replace STRONG_PASSWORD with a long random password. The details are in how to create a database in MySQL and how to create a MySQL user; both apply to MariaDB unchanged.

Keep MariaDB Local

On Debian and Ubuntu, the server configuration is /etc/mysql/mariadb.conf.d/50-server.cnf, and it sets bind-address = 127.0.0.1. On AlmaLinux and Rocky Linux the server options live in /etc/my.cnf.d/, and the packaged files there do not necessarily set an address. Check what the server listens on:

sudo ss -tlnp | grep mariadbd

If port 3306 shows an address other than 127.0.0.1 and your application runs on the same server, add bind-address = 127.0.0.1 under [mysqld] and restart the service. Keep port 3306 closed in the firewall either way. If another server really must connect, follow how to allow remote connections to MySQL.

Service Commands

TaskCommand
Restartsudo systemctl restart mariadb
Stopsudo systemctl stop mariadb
Start at bootsudo systemctl enable mariadb

The main tools also answer to the old names: mysql, mysqldump, and mysqladmin work alongside mariadb, mariadb-dump, and mariadb-admin. On Debian 13 and Ubuntu 26.04, other old names such as mysqlshow need the compatibility package. Schedule a dump of each database before you put data on the server.

Was this answer helpful?
Loading...