Installation and configuration of MariaDB

From Thomas-Krenn-Wiki
Jump to navigation Jump to search

This article describes how to install, secure and perform basic administration tasks with a MariaDB-server on an Ubuntu 24.04 system.

Prerequisites

The installation is made via the official Ubuntu package sources.

Installation of MariaDB

First, the system must be updated to ensure that all package sources are up-to-date:

sudo apt update && sudo apt upgrade -y

After this, the MariaDB server is installed:

sudo apt install mariadb-server -y

After the installation, the service starts automatically. The state can be verified as follows:

systemctl status mariadb

Secure MariaDB (mysql_secure_installation)

There is an integrated safety configuration program included in MariaDB that ensures important basic settings.

You can start it as follows:

sudo mysql_secure_installation

The following steps are questioned:

  • set root-passwort (if empty)
  • remove anonymous users
  • limit root-login on local machine
  • remove testing data base
  • reload privilegies table

It is recommended to confirm all safety questions with yes.

Application on the MariaDB-console

Login as root-user:

sudo mariadb

Terminate the console:

EXIT;

Create own user

A user with password and all rights is created as follows on a certain data base:

CREATE USER 'user'@'localhost' IDENTIFIED BY 'STRONGPASSWORD';

GRANT ALL PRIVILEGES ON data base.* TO 'user'@'localhost';

FLUSH PRIVILEGES;

Administrate MariaDB-service

MariaDB can be controlled as every systemd-service:

systemctl start mariadb

systemctl stop mariadb

systemctl restart mariadb

systemctl enable mariadb

  • start → start service
  • stop → terminate service
  • restart →restart service
  • enable → load automatically during system start

Configuration file

The central configuration file can be found here:

/etc/mysql/mariadb.conf.d/50-server.cnf

Important settings:

  • bind-address
  • max_connections
  • query_cache_size
  • default-storage-engine

After changes:

sudo systemctl restart mariadb

Open MariaDB for firewall (optional)

If external clients should have access to MariaDB (for example other servers), the port 3306 must be released:

sudo ufw allow 3306/tcp

Hint: Only open if absolutely necessary! External data base access should only be made via trustworthy networks or VPN.

Making MariaDB available via network

So that MariaDB is not only available locally, the bind-address must be changed:

Open file:

  sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Adapt value:

  bind-address = 0.0.0.0

Restart service:

  sudo systemctl restart mariadb

Testing the connection

Locally:

mariadb -u root -p

Remote (example on another host):

mariadb -h IP -u benutzer -p

Summary

A complete MariaDB-instance can be installed under Ubuntu 24.04 in just a few steps:

  • update system
  • install MariaDB
  • execute safety configuration
  • create user + data base
  • administrate service
  • optional: release external access

A performant and stable SQL-data base environment is provided.

Troubleshooting

  • Service does not start?
    • Verify log: journalctl -u mariadb
  • access denied?
    • verify user rights: SELECT host, user FROM mysql.user;
  • Remote-access does not function?
    • verify bind-address and user source (host)
  • port 3306 blocked?
    • verify UFW or external firewall

Further articles

Administration

Security


Author: Adrian Zillner

Adrian Zillner has been working in Technical Service at Thomas-Krenn AG since May 2025. He is responsible for supporting customers and answering questions about technical issues.

Translator: Alina Ranzinger

Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.


Related articles

ATA exception Emask
Data Synchronization with rsync under Linux
Reading out DMI hardware infos via sysfs