How To Install MariaDB on Debian 11

Debian 11 is used by many different developers. It is also used on servers that store data using database drivers such as MariaDB. Precisely talking about this last one is that in this post I will show you how to install MariaDB on Debian 11 so if you are a developer you can start working with your applications or even on a server as the first step for other operations.

MariaDB is a database management system. It is a fork of MySQL, one of the most important databases that have ever existed in the market, used to manage large amounts of information.

This relational database manager can be used anywhere MySQL was used before. Therefore, MariaDB can be used in any newly created project, especially in transactional systems.

Among the new features that have already been implemented in MariaDB, we can highlight:

  • New storage engines such as Aria
  • SphinxSE, to make text searches under Sphinx. This is very efficient in the use of resources.
  • MariaDB incorporates other performance improvements and faster and more transparent security versions.

In addition to this, it has support for enterprise and community versions so that we can use it on almost any system.

Install MariaDB on Debian 11

MariaDB is available in the official Debian 11 repositories. So the installation process is really easy.

So, open a terminal and make sure the distribution is completely up to date.

sudo apt update
sudo apt upgrade

After that, we can install it by running the following command.

sudo apt install mariadb-server mariadb-client

The above command will install both the server and the client. Although it is not necessary, sometimes it is useful to have both available.

Then we will be able to configure MariaDB a bit.

Managing the MariaDB service

MariaDB has a systemd service that you can use to easily start, stop, restart, and check the status of the service.

To start the MariaDB service run

sudo systemctl start mariadb

If you make any changes to the MariaDB configuration, you will need to restart MariaDB for them to take effect. You can do this with the following command

sudo systemctl restart mariadb

Also, at times you may feel the need to stop the service to do some kind of operation.

sudo systemctl stop mariadb

Finally, it is useful to know the status of the service to be sure it is running correctly.

sudo systemctl status mariadb

This way you can manage the MariaDB service on the system.

Securing the MariaDB installation on Debian 11

Before using it we need to make sure MariaDB is installed. We can do this by first creating a new password for the root user. Then, by configuring the installation a bit.

At first glance, this may seem complex, but thanks to the mysql_secure_installation script we can make it easy.

sudo mysql_secure_installation

And the first thing we will see is that the script asks us to enter the root user password. As this is a fresh install, just leave it blank:

Enter current password for root (enter for none):

Then we will be asked if we want to change the authentication protocol

Switch to unix_socket authentication [Y/n]

And now yes, change the root password to ours

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables...
... Success!

After the root user’s password has been updated, then we will be asked some configuration questions to answer.

Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Now we have MariaDB ready to use.

To access the shell with the root user, you have to execute

sudo mysql -u -root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.

Now you can use it without problems

Conclusion

MariaDB is a solid alternative to MySQL and has gained its own personality and a stable and professional path that shows the strength of open-source software. Now that you know how to install it, it’s up to you to try it out and take advantage of it.

So, tell us your experience. Like it? leave us a comment and help us grow.

Scroll to Top