MariaDB is the open-source database that powers millions of websites, and version 11.8 LTS is its current long-term support release: fast, stable, and fully compatible with MySQL. Ubuntu 24.04 ships an older MariaDB in its default repositories, so to get 11.8 you install it from MariaDB's official repository instead. This guide walks you through the whole process: adding the official repo, installing the server, locking it down, and creating your first database and user. By the end you will have a production-ready MariaDB 11.8 server running on Ubuntu 24.04.

Prerequisites

  • An Ubuntu 24.04 server (a VPS or local machine) with at least 1 GB of RAM.
  • A user account with sudo privileges.
  • About 15 minutes and a stable internet connection.
  • Basic comfort with the Linux terminal.

If you are still on Ubuntu 22.04, the same steps work, but this guide is written and tested against Ubuntu 24.04 (Noble Numbat).

Step 1: Update Ubuntu and install prerequisites

Start by bringing your package lists and installed packages up to date. This avoids the classic problem of installing against stale repository data.

sudo apt update && sudo apt upgrade -y

The first command refreshes the list of available packages; the second upgrades everything already installed. The -y flag answers "yes" to every prompt so the upgrade runs unattended.

Next, install the small set of tools the MariaDB repository setup needs:

sudo apt install -y curl gnupg software-properties-common apt-transport-https

curl downloads the repository setup script, gnupg handles the repository signing key, and apt-transport-https lets apt fetch packages over HTTPS.

Step 2: Add the official MariaDB repository

Ubuntu 24.04's default repositories ship MariaDB 10.11, which is several major versions behind. MariaDB publishes an official setup script that detects your Ubuntu version, adds the correct repository, and imports its signing key automatically.

curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-11.8"

The script prints the repository it added and the key it imported. The --mariadb-server-version flag pins the repository to the 11.8 LTS series, so future apt upgrade runs will pull 11.8 patch releases but never jump you to a different major version.

Refresh your package lists so apt sees the new repository:

sudo apt update

If this command completes without GPG or "repository not found" errors, the repo is ready.

Step 3: Install MariaDB 11.8 server

With the repository in place, install the server and client packages:

sudo apt install -y mariadb-server mariadb-client

This installs the mariadb-server daemon, the mariadb command-line client, and all required libraries. Confirm the installed version:

mariadb --version

You should see output similar to this:

mariadb Ver 15.1 Distrib 11.8.2-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper

If the version line starts with 11.8, you have the LTS release installed. If it shows 10.11, the official repository was not picked up — re-run Step 2 and check the output of sudo apt update for errors.

Step 4: Start MariaDB and enable it at boot

On Ubuntu, the installer starts MariaDB automatically, but make the behaviour explicit: enable the service so it starts on every boot, then check that it is running.

sudo systemctl enable --now mariadb

enable turns on auto-start at boot; --now also starts the service immediately. Verify the status:

sudo systemctl status mariadb --no-pager

Look for Active: active (running) in the output. You can also confirm the server is listening on its default port with:

sudo ss -tlnp | grep 3306

A line showing 127.0.0.1:3306 means MariaDB is up and accepting local connections.

Step 5: Secure the installation

A fresh MariaDB install is not hardened: it ships with an anonymous user account, a test database, and a root account with no password. MariaDB includes a script that walks you through locking all of that down.

sudo mariadb-secure-installation

Answer the prompts as follows:

  • Enter current password for root: just press Enter (there is no password yet).
  • Switch to unix_socket authentication? Press n if you want to set a root password instead — see the note below. Press y to keep the Ubuntu default, where root can only log in from the operating-system root account.
  • Change the root password? y — set a long, random password and store it in a password manager.
  • Remove anonymous users? y.
  • Disallow root login remotely? y — root should never connect over the network.
  • Remove test database and access to it? y.
  • Reload privilege tables now? y.

On Ubuntu, the root account authenticates through unix_socket by default, which means sudo mariadb logs you in as root with no password prompt. That is safe on a server only you administer, because it ties database root access to operating-system root access. If other people have sudo on this machine, set a root password instead and answer n to the unix_socket question.

Step 6: Create a database and a dedicated user

Never run your application as the root user. Create a database and a dedicated user that only has access to that one database. Log in as root first:

sudo mariadb

Then run these SQL statements, replacing shop_db, shop_user, and the password with your own values:

CREATE DATABASE shop_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'shop_user'@'localhost' IDENTIFIED BY 'ChangeMe_Strong123!';
GRANT ALL PRIVILEGES ON shop_db.* TO 'shop_user'@'localhost';
FLUSH PRIVILEGES;
SHOW DATABASES;
EXIT;

utf8mb4 is the character set you want for modern applications — it stores emoji and every Unicode character correctly. The GRANT line gives the new user full control over shop_db and nothing else. FLUSH PRIVILEGES makes MariaDB apply the changes immediately.

Step 7 (optional): Allow remote connections

Skip this step if your application runs on the same server — local-only access is the secure default. If a separate application server needs to reach this database, open the connection deliberately.

First, edit the server configuration:

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

Find the line bind-address = 127.0.0.1 and change it to:

bind-address = 0.0.0.0

This makes MariaDB listen on all network interfaces instead of only localhost. Save and exit, then create a remote user and restart the service:

sudo mariadb -e "CREATE USER 'shop_user'@'%' IDENTIFIED BY 'ChangeMe_Strong123!'; GRANT ALL PRIVILEGES ON shop_db.* TO 'shop_user'@'%'; FLUSH PRIVILEGES;"
sudo systemctl restart mariadb

Finally, open the port in the firewall. With UFW:

sudo ufw allow from 203.0.113.10 to any port 3306 proto tcp

Replace 203.0.113.10 with your application server's real IP address. Never open port 3306 to the whole internet — a database port exposed publicly will be found and attacked within hours.

Verify it worked

Run these three checks to confirm the installation is healthy:

sudo mariadb -e "SELECT VERSION();"
sudo systemctl is-active mariadb
mariadb -u shop_user -p -e "SHOW DATABASES;"

The first command prints the server version (expect 11.8.x). The second prints active. The third asks for the new user's password and then lists the databases that user can see — shop_db should be among them. If all three pass, MariaDB is installed, running, and ready for your application.

As a final end-to-end test, create a small table and insert a row:

mariadb -u shop_user -p -e "USE shop_db; CREATE TABLE test (id INT PRIMARY KEY, name VARCHAR(50)); INSERT INTO test VALUES (1, 'hello'); SELECT * FROM test; DROP TABLE test;"

If the row comes back as 1 | hello, reads and writes both work.

Common issues & fixes

1. MariaDB fails to start after installation

Check the service log first — it usually names the exact cause:

sudo journalctl -xeu mariadb

The most common cause is a leftover data directory from a previous MySQL or MariaDB install. If this is a fresh server with no data to lose, stop the service, remove the old data directory, and reinstall:

sudo systemctl stop mariadb
sudo rm -rf /var/lib/mysql
sudo apt install --reinstall mariadb-server

A port conflict with an existing MySQL server is the other usual suspect — you cannot run MySQL and MariaDB on port 3306 at the same time. Remove one of them.

2. ERROR 1698 (28000): Access denied for user 'root'@'localhost'

This is not a wrong-password error — it means root is using unix_socket authentication. Log in with sudo instead of as a normal user:

sudo mariadb

If you need password-based root login, run sudo mariadb and then ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('YourStrongPassword');

3. "Unable to locate package mariadb-server"

Apt cannot see the package because the MariaDB repository was not added, or apt update was not run after adding it. Re-run the repository setup script from Step 2, then sudo apt update, and watch for error lines before installing again.

4. GPG error: "The following signatures couldn't be verified" / NO_PUBKEY

The repository signing key was not imported. The setup script imports it automatically, so re-running the Step 2 command usually fixes it. Do not work around this with --allow-unauthenticated — installing unsigned packages defeats the point of the official repository.

5. ERROR 1045 (28000): Access denied for your new user

The user exists but the host or password does not match. Check which accounts exist and from which hosts they may connect:

sudo mariadb -e "SELECT User, Host FROM mysql.user;"

A user created as 'shop_user'@'localhost' cannot connect from another machine, and 'shop_user'@'%' cannot connect from localhost by password unless it was created separately. Re-create the account with the correct host, or grant privileges to the right 'user'@'host' pair.

Conclusion

You now have MariaDB 11.8 LTS running on Ubuntu 24.04, installed from the official repository so you keep receiving security updates for the whole LTS lifetime, secured with the hardening script, and serving a dedicated database and user for your application. From here, the natural next steps are pointing your application at the new database, setting up automated backups with mariadb-dump, and enabling the slow query log once traffic grows.

If you would rather have an expert handle your server setup, backups, and database tuning, XpertBees sets up and manages production Linux servers for businesses — reach out through xpertbees.in and we will take it from here.