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 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 (Linux, Apache, MySQL, and PHP, Python, or Perl) without significant adjustments being required. Debian 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, you will find helpful instructions in our Digital Guide as well as some for setting up MariaDB on Debian 12. If you want to use MongoDB on Debian 10 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 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.

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

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:

sudo apt update
sudo apt upgrade
bash

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:

sudo apt install mariadb-server
bash

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:

sudo mysql_secure_installation
bash

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:

sudo mariadb -u root
bash

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

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

Use the “FLUSH PRIVILEGES” command for security:

FLUSH PRIVILEGES;
sql

Finally, close the shell:

exit
bash

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:

sudo systemctl status mariadb
bash

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

sudo systemctl start mariadb
bash

You’re now free to use MariaDB.

Was this article helpful?
We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top