> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Install MariaDB or MySQL on Ubuntu, Debian and AlmaLinux

> Install MariaDB on Ubuntu or Debian with sudo apt install mariadb-server, or MySQL with mysql-server. Includes AlmaLinux and Rocky steps and how to log in.

To install MariaDB on Ubuntu or Debian, run `sudo apt update` and then `sudo apt install mariadb-server`. On AlmaLinux or Rocky Linux, run `sudo dnf install mariadb-server` and start it with `sudo systemctl enable --now mariadb`. Log in with `sudo mariadb`. For Oracle MySQL on Ubuntu, install `mysql-server` instead and log in with `sudo mysql`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5–10 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | sudo or root access |

## Before you start

* You need a user with `sudo` rights. If you are logged in as `root`, leave out `sudo`. See [create a sudo user](https://help.freakhosting.com/portals/other/how-to-create-a-sudo-user-on-linux.md).
* Update your packages first. See [update Linux packages](https://help.freakhosting.com/portals/other/how-to-update-linux-packages.md).
* Install **either** MariaDB **or** MySQL, not both. Red Hat states that [MariaDB and MySQL cannot be installed on the same host](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/configuring_and_using_database_servers/using-mariadb_configuring-and-using-database-servers) because their packages conflict.

## Which should I use, MariaDB or MySQL?

A database server stores the data for websites and apps, such as WordPress posts or game plugin stats. MariaDB started as a fork of MySQL and uses the same commands, the same port (`3306`) and the same client tools, so most software that "needs MySQL" works with either.

| | MariaDB | MySQL |
| - | - | - |
| Package on Ubuntu / Debian | `mariadb-server` | `mysql-server` (Ubuntu) |
| Package on AlmaLinux / Rocky | `mariadb-server` | `mysql-server` (9), `mysql8.4-server` (10) |
| Service name | `mariadb` | `mysql` (Ubuntu), `mysqld` (AlmaLinux / Rocky) |
| Client command | `mariadb` (also `mysql`) | `mysql` |

Pick MariaDB if you have no reason to choose otherwise. Debian ships MariaDB as its database server. Pick MySQL if your software's documentation asks for MySQL 8 specifically.

### Which version will I get?

| OS | MariaDB | MySQL |
| - | - | - |
| Ubuntu 24.04 LTS | 10.11 | 8.0 |
| Debian 12 | 10.11 | – |
| Debian 13 | 11.8 | – |
| AlmaLinux / Rocky 9 | 10.5 (10.11 as a module) | 8.0 |
| AlmaLinux / Rocky 10 | 10.11 | 8.4 |

Sources: [Debian 13 release notes](https://www.debian.org/releases/trixie/release-notes/whats-new.en.html), [Red Hat Enterprise Linux 10 database servers](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/considerations_in_adopting_rhel_10/dynamic-programming-languages-web-servers-database-servers).

## How to install MariaDB

> [tab] Ubuntu / Debian
>
> **1. Install the package**
>
> ```bash theme={null}
> sudo apt update
> sudo apt install mariadb-server
> ```
>
> The service starts by itself after installation.
>
> **2. Check that it is running**
>
> ```bash theme={null}
> sudo systemctl status mariadb
> ```
>
> Look for `active (running)`. Press `q` to leave.

> [tab] AlmaLinux / Rocky
>
> **1. Install the package**
>
> ```bash theme={null}
> sudo dnf install mariadb-server
> ```
>
> On AlmaLinux or Rocky 9 this installs MariaDB 10.5. For 10.11, run `sudo dnf module install mariadb:10.11/server` instead.
>
> **2. Start it and enable it at boot**
>
> ```bash theme={null}
> sudo systemctl enable --now mariadb
> ```
>
> **3. Check that it is running**
>
> ```bash theme={null}
> sudo systemctl status mariadb
> ```

## How to install MySQL instead

> [tab] Ubuntu
>
> ```bash theme={null}
> sudo apt update
> sudo apt install mysql-server
> sudo systemctl status mysql
> ```

> [tab] AlmaLinux / Rocky 9
>
> ```bash theme={null}
> sudo dnf install mysql-server
> sudo systemctl enable --now mysqld
> ```

> [tab] AlmaLinux / Rocky 10
>
> ```bash theme={null}
> sudo dnf install mysql8.4-server
> sudo systemctl enable --now mysqld
> ```

## How to log in for the first time

On Ubuntu and Debian, the database `root` account uses socket authentication: it trusts your Linux login, so no password is needed when you use `sudo`.

```bash theme={null}
sudo mariadb
```

For MySQL on Ubuntu, use `sudo mysql`. [Ubuntu documents](https://ubuntu.com/server/docs/how-to/databases/install-mysql/) that MySQL's root account "authenticates with auth\_socket". MariaDB's packages work the same way: the [MariaDB documentation](https://mariadb.com/docs/server/security/user-account-management/authentication-from-mariadb-10-4) says root signs in through Unix socket authentication.

You see a prompt such as `MariaDB [(none)]>`. Type `exit` to leave.

If you installed MySQL on AlmaLinux or Rocky, run `sudo mysql_secure_installation` next. [Red Hat's MySQL guide](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_using_database_servers/using-mysql) uses this script to set the root password.

## How to check it worked

```bash theme={null}
sudo mariadb -e "SELECT VERSION();"
```

Expected output on Ubuntu 24.04:

```text theme={null}
+-----------------------------------+
| VERSION()                         |
+-----------------------------------+
| 10.11.14-MariaDB-0ubuntu0.24.04.1 |
+-----------------------------------+
```

The server only listens on `127.0.0.1` (the server itself) after a fresh install on Ubuntu and Debian. That is the safe default. Check with:

```bash theme={null}
sudo ss -ltnp | grep 3306
```

> [!WARNING]
>
> Do not open port `3306` to the whole internet. If an app on another machine needs the database, follow [allow remote MySQL connections](https://help.freakhosting.com/portals/other/how-to-allow-remote-mysql-connections.md) and only allow that machine's IP address.

## What to do next

1. [Secure MySQL and MariaDB](https://help.freakhosting.com/portals/other/how-to-secure-mysql-and-mariadb.md).
2. [Create a database and user](https://help.freakhosting.com/portals/other/how-to-create-a-mysql-database-and-user.md) for each app. Never let apps log in as `root`.
3. [Set up backups](https://help.freakhosting.com/portals/other/how-to-back-up-and-restore-mysql-databases.md) before you store real data.

## Frequently asked questions

### Is MariaDB a drop-in replacement for MySQL?

For most web apps, yes. MariaDB uses the same protocol, port and SQL for everyday tasks. Some newer MySQL 8 features are not in MariaDB, so check your app's requirements if it names a specific MySQL version.

### Why does `mysql -u root -p` say "Access denied" right after install?

On Ubuntu and Debian, root logs in through the Linux socket, not a password. Run `sudo mariadb` or `sudo mysql` instead.

### Can I install MariaDB and MySQL on the same server?

No. The packages conflict. If you need both, run one of them in a container. See [install Docker](https://help.freakhosting.com/portals/other/how-to-install-docker.md).

### How much RAM does MariaDB need?

It depends on the size of your data and how many connections your apps open. Watch usage with [check memory usage](https://help.freakhosting.com/portals/other/how-to-check-memory-usage-on-linux.md) and add [swap space](https://help.freakhosting.com/portals/other/how-to-add-swap-space-on-linux.md) on small plans.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Secure MySQL and MariaDB](https://help.freakhosting.com/portals/other/how-to-secure-mysql-and-mariadb.md)
>
> Run the secure installation script.

> [card] [Create a database and user](https://help.freakhosting.com/portals/other/how-to-create-a-mysql-database-and-user.md)
>
> Give each app its own login.

> [card] [Install a LEMP stack](https://help.freakhosting.com/portals/other/how-to-install-a-lemp-stack.md)
>
> Nginx, PHP and MariaDB together.

> [card] [Install phpMyAdmin](https://help.freakhosting.com/portals/other/how-to-install-phpmyadmin.md)
>
> Manage databases in the browser.

***

> [!NOTE]
>
> **Checked against the official [Ubuntu Server documentation](https://ubuntu.com/server/docs/how-to/databases/install-mysql/), [Red Hat database server guides](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_using_database_servers/using-mariadb) and [MariaDB documentation](https://mariadb.com/docs/server/security/user-account-management/authentication-from-mariadb-10-4)** on 4 November 2026; install and login commands tested on Ubuntu 24.04 LTS with MariaDB 10.11. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.