How To Install and Secure MariaDB 10.5.x on Debian 10

How To Install and Secure MariaDB 10.5.x on Debian 10

Forked from MySQL, created with love by original MySQL developers, MariaDB is one of the most popular open source database platforms to this date. MariaDB is guaranteed to stay open source. In this guide, we are going to see how to install MariaDB 10.5.x on Debian 10 Buster.

Step 1: Add Required Tools

$ apt install curl apt-transport-https wget -y

Step 2: Configure APT Repository

Add MariaDB repository using any text editor. 

$ wget
$ echo "6528c910e9b5a6ecd3b54b50f419504ee382e4bdc87fa333a0b0fcd46ca77338 mariadb_repo_setup" \
       | sha256sum -c -
$ chmod +x mariadb_repo_setup
$ sudo ./mariadb_repo_setup --mariadb-server-version="mariadb-10.5"
$ sudo apt update

Step 3: Install MariaDB

The following command will install the MariaDB server and the client. 

$ apt install mariadb-server mariadb-backup

Step 4: Enable and Start MariaDB service

We are going to enable MariaDB Server to auto start during boot then start the service.

$ systemctl enable mariadb
$ systemctl start mariadb

Step 5: Securing MariaDB

MariaDB comes with a built-in script to help secure a MariaDB server. The requires several user inputs. The following command will start the securing script:

$ mysql_secure_installation

Step 5a: Set root Password

Type in y when asked to set root password and type in the new password twice.

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change root password? [Y/n] y

New password: *******
Re-enter new password: *****
Password updated successfully!
Reloading privilege tables..
... Success!

Step 5b: Remove Anonymous User

Type in y to remove the built-in anonymous user.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Step 5c: Prevent root Access outside localhost

Type in y to disallow root access into the database outside the server itself. 

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!

Step 5d: Remove Built-in Database

Type in y to remove the built-in database named test.

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Step 5e: Apply Privileges

Type in y to apply all the changes thus far. 

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Step 6: Test Database Access

At this point, the MariaDB server is fully configured and ready to serve. Connect to the database to ensure root credential is working. 

$ mysql -u root -p
Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.5.9-MariaDB-1:10.5.9+maria~buster binary distribution

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)]>

Congratulations! Your MariaDB Server 10.5.x is now fully configured and secured on Debian 10. 

MariaDB Configuration Files

MariaDB packages bundled and custom configuration files are stored in the following locations on Debian 10:

Bundled Configuration Files

  • /etc/mysql/my.cnf
  • /etc/mysql/mariadb.cnf
  • /etc/mysql/mariadb.conf.d/50-client.cnf
  • /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
  • /etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf
  • /etc/mysql/mariadb.conf.d/50-server.cnf
  • /etc/mysql/mariadb.conf.d/60-galera.cnf

Custom Configuration Files:

  • /etc/mysql/conf.d
  • /etc/mysql/mariadb.conf.d/

Latest HOW-TOs