Install MariaDB Server on Debian and Adjusting User Authentication and Privileges.

  Databases, Linux

MariaDB is an open-source database engine system, commonly used.
This tutorial will explain how to install MariaDB on a Debian server, and verify that it is running and has a safe initial configuration.

Step 1 — Instalation

Lets start this by updatings our repositories and install the package, and for that we will use the apt command.

apt update
apt install mariadb-server

After the instalation of MariaDB server we wlll do the initial configuration with a simple script that is suplyed with the MariaDB engine instalation.
Because the default configuration leaves your installation of MariaDB insecure, we will use a script that the mariadb-server package provides to restrict access to the server and remove unused accounts.

Step 2 — Configuring MariaDB

For new MariaDB installations, the next step is to run the included security script. This script changes some of the less secure default options. We will use it to block remote root logins and to remove unused database users.

Run the security script:

mysql_secure_installation

This will take you through a wizard, where we can do some changes in the security options of MariaDB installation.
First it will ask to enter the current database root password. Since we have not have not define none, press ENTER to indicate “none”.
The second one asks if we will like to set up a database root password.
In Debian, the root account for MariaDB is tied closely to automated system maintenance, so think well if you should change the configured authentication methods for that account.
The third question will ask if we want to remove all the test databases. In this one we will recommend to press Y.

Step 3 — (Optional) Adjusting User Authentication and Privileges

In Debian systems running MariaDB the root MariaDB user is set to authenticate using the unix_socket by default, rather than with a password.
This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) administrative rights.
Because the server uses the root account for tasks like log rotation and starting and stopping the server, it is best not to change the root account’s authentication details.
Changing credentials in the /etc/mysql/debian.cnf configuration file may work initially, but package updates could potentially overwrite those changes.
Instead of modifying the root account, the package maintainers recommend creating a separate administrative account for password-based access.

To do so, we will create a new account called admin with the same capabilities as the root account, but configured for password authentication. To do this, open up the MariaDB prompt from shell:

mysql

Now, we will create a new user with root privileges and password-based access.

MariaDB [(none)]> GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Flush the privileges to ensure that they are saved and available in the current session:

MariaDB [(none)]> FLUSH PRIVILEGES;

Following this, exit the MariaDB shell:

MariaDB [(none)]> exit

Step 4 — Testing MariaDB

When installed from the default repositories, MariaDB should start running automatically. To test this, check its status.

systemctl status mariadb

You’ll receive output that is similar to the following:

[root@webdb.netostech.com:/home/zeit]# systemctl status mariadb.service
● mariadb.service - MariaDB 10.10.10 database server
    Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Active: active (running) since Sun 2021-07-25 10:44:27 WEST; 3h 44min ago
    Docs: man:mysqld(8)
       https://mariadb.com/kb/en/library/systemd/
Main PID: 12369 (mysqld)
    Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 2358)
    Memory: 72.7M
    CGroup: /system.slice/mariadb.service
       └─12369 /usr/sbin/mysqld

If MariaDB isn’t running, you can start it with the command

systemctl start mariadb.

For an additional check, you can try connecting to the database using the mysqladmin tool, which is a client that lets you run administrative commands. For example, this command says to connect to MariaDB as root and return the version using the Unix socket:

sudo mysqladmin version

If you configured a separate administrative user with password authentication, you could perform the same operation by typing:

mysqladmin -u admin -p version

This means that MariaDB is up and running and that your user is able to authenticate successfully.

And that’s all.
Tanks for reading.