How to Install MariaDB on Debian 11

Install MariaDB on Debian 11

In this article, we will have explained the necessary steps to install MariaDB on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

MariaDB is a fork of MySQL database and is developed as an open-source solution, primarily under the GPL license. MySQL has been replaced with MariaDB in Debian repositories, which is a decent alternative to MySQL and pretty much performs every operation that MySQL performs.


  • Operating System with Debian 11
  • Server IPv4 Address with Superuser Privileges (Root Access)
  • Gnome Terminal for Linux Desktop
  • PuTTy SSH client for Windows or macOS
  • Powershell for Windows 10/11
  • Familiar with APT Commands

Install MariaDB on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade
sudo apt install software-properties-common dirmngr gnupg2
sudo apt install apt-transport-https wget curl

Step 2. Install MariaDB on the Debian Bullseye system.

Run the following command below to install MariaDB on your Debian:

sudo apt install mariadb-server

You can verify the installed version of MariaDB with the following command:

mariadb --version

Once the installation of MariaDB is complete, start and enable it. Start it with the command of systemctl:

sudo systemctl start mariadb
sudo systemctl stop mariadb
sudo systemctl restart mariadb

Step 3. Secure MariaDB Installation.

MariaDB comes with a default security script, mysql_secure_installationthat is used to improve the security of MariaDB installation by:

  • Setting the password for root accounts (if need be).
  • Disabling remote root login to the databases.
  • Removing anonymous-user accounts.
  • Removing the test database, which by default can be accessed by anonymous users.

Now, to secure MariaDB, execute the below-mentioned command:

sudo mysql_secure_installation

Install MariaDB on Debian 11

Now to verify the security we will run the following command to enter the environment of MariaDB and then type the set password to access it:

sudo mysql -u root -p

Step 4. Creating a New Administrative User.

Now create a new administrative user. This will be the first user to access your MariaDB server after installation. Run the following statement to create a new user with a username of linuxtips, and with a password of [email protected]. Feel free to change the username and password to suit your needs:

GRANT ALL ON *.* TO 'linuxtips'@'localhost' IDENTIFIED BY '[email protected]' WITH GRANT OPTION;

Step 5. Reset the MariaDB Root Password.

If you forget your root MariaDB password, it can be reset:

sudo systemctl stop mariadb

Next, start the database without loading the grant tables or enabling networking:

sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-networking"

Restart MariaDB:

sudo systemctl start mariadb

Then, connect to the database as the root user:

sudo mysql -u root

Run the following commands to reset root’s password. Replace password with a strong password:

MariaDB [(none)]> UPDATE mysql.user SET password = PASSWORD('password') WHERE user = 'root';

Update the authentication methods for the root password:

MariaDB [(none)]> UPDATE mysql.user SET authentication_string = '' WHERE user = 'root';
MariaDB [(none)]> UPDATE mysql.user SET plugin = '' WHERE user = 'root';

Revert the environment settings to allow the database to start with grant tables and networking:

sudo systemctl unset-environment MYSQLD_OPTS

Finally, restart MariaDB:

sudo systemctl start mariadb

That’s all you need to do to install the MariaDB on Debian (Bullseye). I hope you find this quick tip helpful. For further reading of the MariaDB database on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.