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
2. Install the MariaDB server package:
$ sudo apt install mariadb-server -y
3. Verify the installed version:
$ mariadb --version
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
2. Check the service status:
$ sudo systemctl status mariadb
3. Stop or restart the service when needed:
$ sudo systemctl stop mariadb
$ sudo systemctl restart mariadb
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
Restart MariaDB to apply the changes:
$ sudo systemctl restart mariadb
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
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;
Create a Sample Table
Log in as the new user to verify database access and permissions.
$ mariadb -u myapp_user -p myapp_db
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;
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)