Back to all guides
Databases

Setting Up MariaDB Database

4 read2026-04-09

MariaDB is a powerful, open-source relational database management system that serves as a highly compatible drop-in replacement for MySQL. This guide will walk you through installing the latest version of MariaDB natively.

Hosting Tip: Production databases require high I/O throughput and low disk latency. We recommend hosting on a KVM Root Server with PCIe 4.0 NVMe SSDs in RAID with dedicated resources, ECC memory, and full root access.

1. Adding the Official MariaDB Repository

The default package repositories for your OS often contain older versions of MariaDB. To get the newest release, we need to add the official MariaDB repository.

bash
# Install required software-properties-common package
sudo apt-get install software-properties-common dirmngr apt-transport-https -y

# Download and add the MariaDB GPG signing key
sudo curl -LsSO https://mariadb.org/mariadb_release_signing_key.asc
sudo chmod -c 644 mariadb_release_signing_key.asc
sudo chown root:root mariadb_release_signing_key.asc
sudo mv mariadb_release_signing_key.asc /etc/apt/trusted.gpg.d/

# Add the repository for the latest version (Example for Ubuntu 22.04/24.04 and MariaDB 11.4)
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.xtom.de/mariadb/repo/11.4/ubuntu focal main'

(Note: Always check the MariaDB official repository tool for the exact repository link corresponding to your specific Linux distribution and the absolute latest MariaDB version).

2. Installing MariaDB

Once the repository is added, update your package lists and install the database server.

bash
sudo apt update
sudo apt install mariadb-server mariadb-client -y

Verify the installation and check the version:

bash
mariadb --version

3. Securing the Installation

MariaDB comes with a security script that helps you remove unsafe default settings, such as remote root login and anonymous users.

Run the secure installation wizard:

bash
sudo mariadb-secure-installation

You will be prompted to answer several questions:

  • Current root password: Press Enter (since none is set yet).
  • Switch to unix_socket authentication: Y
  • Change the root password: Y (Set a very strong password!)
  • Remove anonymous users: Y
  • Disallow root login remotely: Y
  • Remove test database: Y
  • Reload privilege tables: Y

4. Creating a New Database and User

It's bad practice to use the root user for your applications. Instead, create a dedicated user and database for each app.

Log into the MariaDB shell as root:

bash
sudo mariadb

Create a database and a user (replace myappdb, appuser, and securepassword with your own values):

sql
-- Create a new database
CREATE DATABASE myappdb;

-- Create a new user configured to connect from localhost
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'securepassword';

-- Grant all privileges on the new database to the new user
GRANT ALL PRIVILEGES ON myappdb.* TO 'appuser'@'localhost';

-- Apply the changes
FLUSH PRIVILEGES;

-- Exit the shell
EXIT;

5. Managing the MariaDB Service

Use systemctl commands to control your database server:

bash
# Check the status of MariaDB
sudo systemctl status mariadb

# Restart the service
sudo systemctl restart mariadb

# Ensure MariaDB automatically starts on system boot
sudo systemctl enable mariadb
KVM Linux VPS

Looking for the right Linux VPS?

Put your project into practice right away: Our KVM VPS provide full root access, lightning-fast NVMe storage, and reliable KVM isolation. Flexible prepaid billing with no subscription and personal Discord support.

Full Root Access (SSH)
Datacenter NVMe SSD
4+ Tbps DDoS Protection
100% Prepaid (No Subscription)