# How to install MariaDB on Ubuntu 24.04

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

## Why install MariaDB on Ubuntu 24.04?

Ubuntu 24.04 ‘Noble Numbat’ is a modern, stable and long-term supported Linux distribution. [MariaDB](https://www.ionos.co.uk/digitalguide/server/know-how/what-is-mariadb/) offers advanced features, better performance than **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](https://www.ionos.co.uk/digitalguide/server/configuration/linux-sudo-command/) 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:

```bash
sudo apt update && sudo apt upgrade -y
```

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:

```bash
sudo apt install mariadb-server -y
```

### Step 3: Start and enable the MariaDB service

Start the MariaDB service using the following command:

```bash
sudo systemctl start mariadb
```

Enable the service so MariaDB automatically runs at system startup:

```bash
sudo systemctl enable mariadb
```

Check its status:

```bash
sudo systemctl status mariadb
```

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 tool**:

```bash
sudo mariadb_secure_installation
```

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 unauthorised access.

Tip You can also restrict access to MariaDB port 3306 by allowing only trusted [IP Addresses](https://www.ionos.co.uk/digitalguide/server/know-how/what-is-an-ip-address/). 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:

```bash
sudo mariadb -u root -p
```

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:

```sql
CREATE DATABASE db_example;
```

Now create a user account that can access this database:

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

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

Grant permissions to the user on the new database:

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

This gives the user full access to the `db_example` database.

Finally, activate the privileges immediately with:

```sql
FLUSH PRIVILEGES;
```

Exit the shell with:

```sql
EXIT;
```

### Step 6: Test access

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

```bash
mariadb -u webuser -p db_example
```

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:

```sql
SHOW TABLES;
```

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


This is a markdown version of: [https://www.ionos.co.uk/digitalguide/hosting/technical-matters/install-mariadb-ubuntu-2404/](https://www.ionos.co.uk/digitalguide/hosting/technical-matters/install-mariadb-ubuntu-2404/) for AI/LLM consumption.