# How to install MariaDB on Debian 11

In order to install MariaDB on Debian 11, the following steps are required:

1. Update your Debian 11 installation.
2. Install MariaDB.
3. Customize the configuration according to your requirements.
4. Create an additional admin user (optional).
5. Check whether the installation was successful.

## Why are MariaDB and Debian 11 a good fit?

In the [MariaDB vs. MySQL](https://www.ionos.com/digitalguide/hosting/technical-matters/mariadb-vs-mysql/) comparison, MariaDB has long since proven itself. This SQL server is known for being extremely robust, highly secure, and generally more flexible than the older database management system of the same origin. Designed as a direct **drop-in replacement for MySQL**, it can be used as a MySQL substitute within the [LAMP stack](https://www.ionos.com/digitalguide/server/know-how/lamp-servers-the-solution-for-dynamic-websites/) (Linux, Apache, MySQL, and PHP, Python, or Perl) without significant adjustments being required. [Debian](https://www.ionos.com/digitalguide/server/know-how/debian-the-universal-system-software/) has also been using MariaDB for quite some time and contains the necessary packages by default.

Tip If you want to [install MariaDB on Debian 10](https://www.ionos.com/digitalguide/hosting/technical-matters/install-mariadb-on-debian-10/), you will find helpful instructions in our Digital Guide as well as some for [setting up MariaDB on Debian 12](https://www.ionos.com/digitalguide/hosting/technical-matters/install-mariadb-on-debian-12/). If you want to [use MongoDB on Debian 10](https://www.ionos.com/digitalguide/websites/web-development/install-mongodb-debian/) instead, we will also guide you through all the necessary steps.

## What requirements must be met?

There are only a few requirements that need to be met to install MariaDB installation on Debian 11. The first is that you need a server that Debian 11 is already installed on. Root access for this server is required and a suitable [firewall](https://www.ionos.com/digitalguide/server/security/what-is-a-firewall/) should be set up and activated. As a rule, one CPU core is sufficient. In addition, at least **512 megabytes of RAM and 1 gigabyte of hard disk space** are required.

## How to install MariaDB on Debian 11 step by step

The following sections show you step by step how to install MariaDB on Debian 11.

### Step 1: Update the package index

Before you start the actual installation, you should make sure that all your programs and Debian 11 itself are up to date. To do this, update the package index with these two `apt` commands:

```bash
sudo apt update
sudo apt upgrade
```

Once this is done, you can start installing MariaDB on Debian 11.

### Step 2: Install MariaDB on Debian 11

Use the following command to install the package for MariaDB:

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

Once this process is complete, it means you have installed MariaDB on Debian 11, but no security precautions have yet been taken for your system. This part comes in the next step.

### Step 3: Execute the security script

MariaDB offers its own security script for its newer versions. You can use this script to modify some default settings. The command to initiate the script is as follows:

```bash
sudo mysql_secure_installation
```

When you start the script, you’ll first be prompted to enter your root password for the database. Since you haven’t set this up yet, press \[Enter\] to **skip this step for now**. Then, you will be asked if you want to switch to authentication via unix\_socket. Type \[N\] and press \[Enter\] to confirm.

You will be asked if you want to change your root password. However, this is not recommended **for security reasons**, so press \[N\] and \[Enter\] again. Answer the following questions with \[Y\] to remove anonymous users, the test database and root logins remotely.

### Step 4: Set up an additional admin (optional)

The next step is optional but highly recommended for securing your system. In Debian 11, the MariaDB root user is authenticated using unix\_socket instead of a password. Although this has some benefits, it can cause problems when external programs need admin rights. A solution is to **create an additional admin user** to complement the root account. Here are the steps to do this:

Open the MariaDB shell:

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

Now create the new user. Change the username and password as required.

```sql
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
```

Use the “FLUSH PRIVILEGES” command for security:

```sql
FLUSH PRIVILEGES;
```

Finally, close the shell:

```bash
exit
```

### Step 5: Check whether the installation was successful

Finally, check whether the installation of MariaDB on Debian 11 was a success. To do this, test the status with this command:

```bash
sudo systemctl status mariadb
```

If MariaDB does not start automatically, use the following command:

```bash
sudo systemctl start mariadb
```

You’re now free to use MariaDB.


This is a markdown version of: [https://www.ionos.com/digitalguide/hosting/technical-matters/install-mariadb-on-debian-11/](https://www.ionos.com/digitalguide/hosting/technical-matters/install-mariadb-on-debian-11/) for AI/LLM consumption.