How to Install MariaDB on Debian 10

MariaDB is an open source, multi-threaded relational database management system, backward compatible replacement for MySQL. MariaDB is the default implementation of MySQL in Debian.

Installing MariaDB on Debian 10

Perform the following steps as root or user with sudo privileges to install MariaDB on Debian 10:

Start by updating the packages index:

sudo apt update

Install the MariaDB server and client packages by running the following command:

sudo apt install mariadb-server

The MariaDB service will start automatically. To verify it check the service status:

sudo systemctl status mariadb

The output should look something like this:

● mariadb.service - MariaDB 10.3.15 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-07-11 14:36:28 PDT; 19min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 4509 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 2359)
   Memory: 78.6M
   CGroup: /system.slice/mariadb.service
           └─4509 /usr/sbin/mysqld  

Securing MariaDB

MariaDB comes with a script that can help you improve the security of installation. To start the script type mysql_secure_installation in your terminal:

sudo mysql_secure_installation


You will be prompted you to set a password for the root account, remove the anonymous user, restrict root user access to the local machine and remove the test database.

Output
...
Enter current password for root (enter for none):
...
Set root password? [Y/n] Y
New password:
Re-enter new password:
...
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
...
Thanks for using MariaDB!


If selected, the script will reload the privilege tables ensuring that the changes take effect immediately.

All steps are explained in detail and it is recommended to answer “Y” (yes) to all questions.

Authentication Methods


By default, the MariaDB root user uses the unix_socket authentication plugin which checks the effective user id when calling the mysql client tool.

This means that you can connect to the MariaDB server as root only if you are invoking the mysql command as system root or by prepending sudo to the command.

For increased security, it is recommended to keep the default authentication plugin and allow the root user to authenticates only via Unix sockets.

If you want to change the root authentication to the classic one, log in to the MariaDB server:

sudo mysql

Run the following statements to change the authentication plugin:

ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_root_passwd';


You can now connect to the MariaDB server using the new password:

mysql -u root -p


Changing the authentication plugin will also allow you to log in as root from an external program such as phpMyAdmin

0 Komentar