MariaDB can be set up and run reliably on Ubuntu 24.04 in just a few steps:

  1. Update Ubuntu

  2. Install MariaDB server via the official package sources

  3. Secure the installation with the integrated security assistant

  4. Start the database service and check for correct functionality

  5. Create a user account and test access

Managed Database Services
Time-saving database services
  • Enterprise-grade architecture managed by experts
  • Flexible solutions tailored to your requirements
  • Leading security in ISO-certified data centers

Why install MariaDB on Ubuntu 24.04?

Ubuntu 24.04 “Noble Numbat” is a modern, stable and long-term supported Linux distribution. MariaDB offers advanced features, better performance compared to MySQL and is fully open source. The combination is especially suitable for web servers, development environments or as a database backend for applications like WordPress, Nextcloud or Home Assistant.

What are the requirements?

Before you start, make sure the following prerequisites are met:

  • A system with Ubuntu 24.04 (Server or Desktop)
  • Root access or a user with sudo privileges
  • Terminal or SSH access

How to install Ubuntu 24.04 on MariaDB

In this tutorial, we explain how to install MariaDB on Ubuntu 24.04. If you are using an older version, we recommend checking out our other guides.

Step 1: Update the system

Start by updating your Ubuntu system. This ensures that all packages are up to date and helps avoid conflicts during installation:

sudo apt update && sudo apt upgrade -y
bash

This command refreshes the package lists and installs all available updates.

Step 2: Install MariaDB on Ubuntu

MariaDB is included in the official Ubuntu repository. You can install it directly using APT:

sudo apt install mariadb-server -y
bash
Compute Engine
The ideal IaaS for your workload
  • Cost-effective vCPUs and powerful dedicated cores
  • Flexibility with no minimum contract
  • 24/7 expert support included

Step 3: Start and enable the MariaDB service

Start the MariaDB service using the following command:

sudo systemctl start mariadb
bash

Enable the service so MariaDB automatically runs at system startup:

sudo systemctl enable mariadb
bash

Check its status:

sudo systemctl status mariadb
bash

You should see output showing that the service is active (running). If so, MariaDB has been successfully installed and started.

Step 4: Secure MariaDB

By default, MariaDB is relatively open after installation. To make it more secure, run the built-in security script:

sudo mariadb_secure_installation
bash

Follow the on-screen instructions. You can, among other things:

  • Set a root password
  • Remove anonymous user accounts
  • Disable remote root access
  • Remove the test database
  • Reload the privilege tables

Type y to confirm each change. This makes your MariaDB Ubuntu installation significantly more secure against unauthorized access.

Tip

You can also restrict access to MariaDB port 3306 by allowing only trusted IP addresses. For example, to allow an internal company subnet use: sudo ufw allow from 192.168.0.0/24 to any port 3306. If only local use is planned, run: sudo ufw deny 3306.

Step 5: Create a user and a database

Log in to the MariaDB console:

sudo mariadb -u root -p
bash

Enter the root password you set earlier. You are now in the MariaDB shell and can execute commands.

Create a new database, for example for a web application or a CMS:

CREATE DATABASE db_example;
sql

Now create a user account that can access this database:

CREATE USER 'webuser'@'localhost' IDENTIFIED BY 'safepassword';
sql

Replace webuser and safepassword with your own details. Make sure to use a secure password.

Grant permissions to the user on the new database:

GRANT ALL PRIVILEGES ON db_example.* TO 'webuser'@'localhost';
sql

This gives the user full access to the db_example database.

Finally, activate the privileges immediately with:

FLUSH PRIVILEGES;
sql

Exit the shell with:

EXIT;
sql

Step 6: Test access

Now test if the new user can connect to the database:

mariadb -u webuser -p db_example
bash

Enter the password you set earlier. If successful, you’ll be logged into the MariaDB shell. Inside the shell, run a simple command to confirm access:

SHOW TABLES;
sql

Since no tables exist yet, the database will be empty. This test confirms that the setup and permissions are working correctly.

Was this article helpful?
Go to Main Menu