DEV Community

Cover image for Installing MariaDB on Ubuntu 26.04
Sanskriti Harmukh for Vultr

Posted on • Originally published at docs.vultr.com

Installing MariaDB on Ubuntu 26.04

MariaDB is a drop-in replacement for MySQL that remains fully open source under the GPL license, available directly from Ubuntu 26.04's default APT repository with no external sources required. This guide covers installation, service configuration, security hardening with mariadb-secure-installation, and basic database operations to confirm a working setup.


Install MariaDB

MariaDB is available directly in Ubuntu 26.04's default APT repository.

1. Update the APT package index:

$ sudo apt update
Enter fullscreen mode Exit fullscreen mode

2. Install the MariaDB server package:

$ sudo apt install mariadb-server -y
Enter fullscreen mode Exit fullscreen mode

3. Verify the installed version:

$ mariadb --version
Enter fullscreen mode Exit fullscreen mode

Manage the MariaDB Service

Enable MariaDB as a systemd service so it starts automatically on every boot.

1. Enable and start the service:

$ sudo systemctl enable mariadb
$ sudo systemctl start mariadb
Enter fullscreen mode Exit fullscreen mode

2. Check the service status:

$ sudo systemctl status mariadb
Enter fullscreen mode Exit fullscreen mode

3. Stop or restart the service when needed:

$ sudo systemctl stop mariadb
$ sudo systemctl restart mariadb
Enter fullscreen mode Exit fullscreen mode

Secure MariaDB

The mariadb-secure-installation script removes default configuration risks including anonymous users, remote root login, and the test database.

$ sudo mariadb-secure-installation
Enter fullscreen mode Exit fullscreen mode

Restart MariaDB to apply the changes:

$ sudo systemctl restart mariadb
Enter fullscreen mode Exit fullscreen mode

Create a Database and User

Log in as root and create a dedicated database with a user scoped to that database only.

$ sudo mariadb -u root -p
Enter fullscreen mode Exit fullscreen mode
MariaDB [(none)]> CREATE DATABASE myapp_db;
MariaDB [(none)]> CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'secure_password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Enter fullscreen mode Exit fullscreen mode

Create a Sample Table

Log in as the new user to verify database access and permissions.

$ mariadb -u myapp_user -p myapp_db
Enter fullscreen mode Exit fullscreen mode
MariaDB [myapp_db]> CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    role VARCHAR(100),
    department VARCHAR(100)
);
MariaDB [myapp_db]> MariaDB [myapp_db]> INSERT INTO employees (name, role, department) VALUES
    ('Alice', 'Engineer', 'Backend'),
    ('Bob', 'Designer', 'Frontend'),
    ('Carol', 'DevOps', 'Infrastructure');
MariaDB [myapp_db]> SELECT * FROM employees;
MariaDB [myapp_db]> EXIT;
Enter fullscreen mode Exit fullscreen mode

All three rows in the query output confirm the database, user, and table are working correctly.


Next Steps

MariaDB is now installed and accepting connections. From here you can:

  • Use MariaDB as the database layer in a LAMP or LEMP stack
  • Set up Galera Cluster for multi-master replication
  • Automate backups with mariadb-dump

For the full guide with additional tips, visit the original article on Vultr Docs.

Top comments (0)