Mariadb is a community database management system (DBMS) of Mysql. In this procedure, we will see how to install MariaDB on a Debian 11 machine.
Prerequisites to install MariaDB on Debian 11 :
- A Debian 11 machine (Bullseye) (Debian 11 virtual machine with VirtualBox)
Install MariaDB on Debian 11:
Before we start installing Mariadb on our Debian machine, we will first update the list of packages on our machine.
sudo apt update
Then we will install the server and client packages of Mariadb:
sudo apt install mariadb-server mariadb-client -y
Then we will activate the mariadb service and start it
sudo systemctl enable mariadb sudo systemctl start mariadb
Then we check that the service is started and active:
sudo systemctl status mariadb
Once these steps are done, we can configure Mariadb.
Enter current password for root (enter for none): Change the root password? [Y/n] Y New password: your_pwd Re-enter new password: your_pwd 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
After filling in the questionnaire we can connect to the DBMS using the root user and the password chosen previously.
mariadb -u root -p
Then you will be asked for your password and you will be able to execute your SQL queries.
The first thing to do is to create another user that will have less permissions than the root user.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
“username” is the user name
“user_password” is the user’s password
Then you will have to assign permissions to your user using the GRANT query (example to be adapted according to your needs):
GRANT ALL PRIVILEGES ON *.* to 'username'@'localhost';
Finally we apply the privileges:
And finally we can leave the console mariadb:
The choice of permissions is important for the security of your database and your applications that use that database.
You can also use a certificate authentication system if the machine that contains your application is not on the same machine as the database server.
Use a firewall (like UFW) to limit access to your database server.
If you get errors when executing requests, make sure you put a “;” at the end of the request.