Home » How To » How To Install MariaDB on Debian Linux

How To Install MariaDB on Debian Linux

MySQL is a well-liked free database management system and also a prominent component of the LAMP stack. 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.

MySQL is currently not available for Debian 11 Bullseye, so MariaDB is a perfect choice. This article is focusing on how to install MariaDB, an alternative to MySQL on Debian 11.

Install MariaDB on Debian 11

The MariaDB packages are available under the official repositories. You can directly install it without adding an extra repo to your system. For this tutorial, we will install MariaDB on Debian 11 system via default repositories.

Firstly, update the packages list using:

sudo apt update 

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

sudo apt install mariadb-server 

Configure MariaDB on Debian

To configure MariaDB properly we need to run a security script using the below-mentioned command:

sudo mysql_secure_installation 

After running the above command, you will be prompted with various options:

Related:  How to Install PHP on Ubuntu 20.04

 

mysql-secure-installation-wizzard-1-mytechmint

 

mysql-secure-installation-wizzard-2-mytechmint

The options are self-explanatory, for the first two options choose “n” and for the next sequence of options press “y” for yes.

Create Privileges User with Authentication

For security purposes, MariaDB uses a unix_socket plugin to authenticate the root user. This may cause complications therefore, it is recommended to set a new user with password-based access. And to create a new user login to MariaDB using:

sudo mysql  

Now create a new user with a password in the MariaDB server.

CREATE USER 'admin'@'localhost' IDENTIFIED BY '_pa$$w0rd_'; 

Make sure to change admin with your username and _pas$$w0rd_ with a new secure password.

Next, grant permissions on all databases to a newly created account. Here the GRANT OPTION allow a user to create other users and assign them permissions.

GRANT ALL ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;  

Apply the new changes, execute:

FLUSH PRIVILEGES;  

And to quit typing “exit”.

EXIT 

The SQL statements are case insensitive, So you can write them in any case.

Related:  How to Set Up a Firewall with UFW on Ubuntu

Connect MariaDB Server

One can manage MariaDB service using the Systemd. To test the status of MariaDB use the following command:

sudo systemctl status mariadb 

If for some reasons MariaDB is not running then use the below-mentioned command to start it:

sudo systemctl start mariadb 

For one more check you can try to connect to the database using:

sudo mysqladmin version 
Output:
mysqladmin  Ver 9.1 Distrib 10.5.11-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version          10.5.11-MariaDB-1
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /run/mysqld/mysqld.sock
Uptime:                 3 hours 45 min 24 sec

Threads: 1  Questions: 497  Slow queries: 0  Opens: 171  Open tables: 28  Queries per second avg: 0.036

Next, connect to the MySQL shell by using the credentials created in the above step.

mysql -u admin -p 

The output of the above command asks for the password; use the password you set in the above steps. On successful authentication, you will get the MariaDB shell as below:

Output:
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 60
Server version: 10.5.11-MariaDB-1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

That’s it we learned how to install and configure MariaDB on Debian. We also created a separate user to manage the database with password access. Finally, we also discussed utilities to test the MariaDB status. Feel free to use comment box in case of any query 😎

Leave a Comment