How To Install MySQL/MariaDB on Debian 11

If you are a developer you must have heard about MariaDB as well as the MYSQL database. These two databases are among the most popular and widely used databases in the world. Both are open source as well as relational databases.

MySQL was developed in 1995 and was the only database that was open source, free. MySQL follows a relational database management system that helps us, developers, in making the data store in an organized manner. Apart from this MySQL has its own language which is called SQL language to write queries to the database.

MariaDB is like MySQL but it is the improved version of it. What’s makes MariaDB amazing is its inbuilt powerful features, security improvements as well as many usabilities. It was made out of fear from the MySQL developers as they thought that MySQL will not be free for much longer because of the Oracle acquiring.

Now that we know about the two most amazing databases, let us continue and take a step forward. In this article, we will hold you from your finger and walk you through each and every step to install MySQL and MariaDB on Debian 11.

Installing MariaDB/MySQL on Debian 11

The first step in installing MariaDB/MySQL on Debian 11 is to update the package index by using the apt. For this purpose type the following command in your Debian 11 Terminal:

$ sudo apt update

After updating the package index, let us first install the maria-DB server package.

MariaDB installation

To install MariaDB on Debian 11 type the following command in your Debian 11 terminal:

$ sudo apt install mariadb-server

The above command will install MariaDB on our system. To verify the installation type the following command in your Debian Terminal:

$ mariadb --version

Installing MySQL

Default Debian repository doesn’t have MySQL. So we have to get MySQL APT repository first. For this purpose type the following command:

$ wget

After this type the following command to install MySQL apt specific version:

$ sudo dpkg -i mysql-apt-config_0.8.18-1_all.deb

You will see that a new window is opened. In this window, you are given some options. Select the Debian buster and then click ok.

Once done you will see the following output:

The next step involves updating the package index for which use the following command:

$ sudo apt install mysql-server

You will be asked to enter a password. Enter the password and press Enter.

Starting MariaDB/MySQL

Now that we have successfully installed MariaDB and MySQL on Debian 11, let us start  MariaDB with the following command:

$ sudo systemctl start mariadb

To enable MariaDB type the following command in your Debian 11 Terminal:

$ sudo systemctl enable mariadb

MySQL is automatically started. We can check the status by the following command:

$ sudo systemctl status mysql

To exit press CTRL+C.

MariaDB/MySQL configuration

The default configurations of MariaDB/MySQL are insecure and hence we will make it secure by restricting access and removing unused accounts. Type or copy the following command in your Debian 11 Terminal:

$ sudo mysql_secure_installation

It will ask a series of questions and depending on your preference you can set them. To indicate none or use default value we will press Enter. We set the configurations like shown below:

  • Set root password? Enter
  • Switch to unix_socket. Y
  • Change the root password? Y
  • Remove anonymous users? Y
  • Disallow root login remotely? Y
  • Remove test database access to it? Y

Now we will be able to connect to the Maria DB server with the password set in the above commands. To connect to the MariaDB server type the following command in your terminal:

$ mysql -u root -p

If you followed this guide for MySQL then you will see MySQL for the above command:

Congratulations! We have successfully installed MariaDB/MySQL on Debian 11. To exit the database type exit and you will see the message bye::


MySQL and MariaDB are very popular among developers as both are free and relational databases. The relational database keeps our data in tables and makes it more organized.

In this article, we guided you on how to install both MariaDB as well as MySQL on Debian 11. We hope that you can now install and use these amazing databases.