Install MariaDB 10.7 on Debian 11/Debian 10

In this tutorial, you will learn how to install MariaDB 10.7 on Debian 11/Debian 10. According to MariaDB releases page, “MariaDB 10.7 is the current development series of MariaDB. It is an evolution of MariaDB 10.6 with several entirely new features. MariaDB 10.7.1 is a Release Candidate (RC) release”.

As of this writing, it is not recommended to use this version on production.

Install MariaDB 10.7 on Debian 11/Debian 10

The default Debian 11 repositories provide up-to MariaDB 10.5 packages.

apt-cache policy mariadb-server
mariadb-server:
  Installed: (none)
  Candidate: 1:10.5.12-0+deb11u1
  Version table:
     1:10.5.12-0+deb11u1 500
        500 http://deb.debian.org/debian bullseye/main amd64 Packages

While the default Debian 10 repositories provide up-to MariaDB 10.3 packages;

apt-cache policy mariadb-server
mariadb-server:
  Installed: (none)
  Candidate: 1:10.3.31-0+deb10u1
  Version table:
     1:10.3.31-0+deb10u1 500
        500 http://deb.debian.org/debian buster/main amd64 Packages
     1:10.3.25-0+deb10u1 500
        500 http://security.debian.org/debian-security buster/updates/main amd64 Packages

To install MariaDB 10.7 on Debian 11/Debian 10, therefore;

Install MariaDB APT Repositories

To install MariaDB APT repositories, you need to install some of the required packages;

apt install software-properties-common dirmngr apt-transport-https -y

Install MariaDB repository gpg signing key;

wget -qO- https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/mariadb.gpg

Next, install the MariaDB 10.7 repository on Debian 11/Debian 10.

echo "deb [arch=amd64,i386,arm64,ppc64el] https://mirror.rackspace.com/mariadb/repo/10.7/debian $(lsb_release -sc) main" > /etc/apt/sources.list.d/mariadb.list

You can obtain the mirrors by navigating to MariaDB Repositories and:

  1. Choose your system distribution, for example, Debian 10 “buster”,
  2. Select the version of MariaDB you want to install, for example MariaDB 10.7 [RC]
  3. Choose your preferred repository mirror, ideally that is close to your region.

Next, update your system package cache;

apt update

You now have MariaDB 10.7 provided by the repos;

apt-cache policy mariadb-server
mariadb-server:
  Installed: (none)
  Candidate: 1:10.7.1+maria~bullseye
  Version table:
     1:10.7.1+maria~bullseye 500
        500 https://mirror.rackspace.com/mariadb/repo/10.7/debian bullseye/main amd64 Packages
        500 https://mirror.rackspace.com/mariadb/repo/10.7/debian bullseye/main i386 Packages
        500 https://mirror.rackspace.com/mariadb/repo/10.7/debian bullseye/main arm64 Packages
        500 https://mirror.rackspace.com/mariadb/repo/10.7/debian bullseye/main ppc64el Packages
     1:10.5.12-0+deb11u1 500
        500 http://deb.debian.org/debian bullseye/main amd64 Packages

Install MariaDB 10.7 on Debian 11/Debian 10

You are now ready to install MariaDB 10.7 on Debian 11/Debian 10 by executing the command below;

apt install mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  galera-4 gawk libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mariadb-perl libdbi-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmariadb3 libmpfr6 libpmem1 libreadline5
  libsigsegv2 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client-10.7 mariadb-client-core-10.7 mariadb-common mariadb-server-10.7 mariadb-server-core-10.7
  mysql-common psmisc rsync socat
Suggested packages:
  gawk-doc libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx mariadb-test netcat-openbsd
The following NEW packages will be installed:
  galera-4 gawk libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mariadb-perl libdbi-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmariadb3 libmpfr6 libpmem1 libreadline5
  libsigsegv2 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client-10.7 mariadb-client-core-10.7 mariadb-common mariadb-server mariadb-server-10.7
  mariadb-server-core-10.7 mysql-common psmisc rsync socat
0 upgraded, 35 newly installed, 0 to remove and 73 not upgraded.
Need to get 29.9 MB of archives.
After this operation, 224 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Running MariaDB on Debian 11/Debian 10

When installed, MariaDB is started and enabled to run on system boot;

systemctl status mariadb
● mariadb.service - MariaDB 10.7.1 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Mon 2021-11-29 20:57:03 EAT; 26min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 1828 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 1829 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 1831 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-en>
    Process: 1891 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 1893 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 1878 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 9 (limit: 4678)
     Memory: 96.0M
        CPU: 3.280s
     CGroup: /system.slice/mariadb.service
             └─1878 /usr/sbin/mariadbd

Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: performance_schema
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: sys
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: Phase 6/7: Checking and upgrading tables
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: Processing databases
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: information_schema
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: performance_schema
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: sys
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: sys.sys_config                                     OK
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Nov 29 21:13:44 debian11 /etc/mysql/debian-start[1898]: OK

Securing MariaDB

MariaDB comes with a script that enables you to perform initial security measures.

The script is named mysql_secure_installation and it enables you to improve the security of your MariaDB installation in the following ways:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database, which by default can be accessed by anonymous users.

The script can be invoked without any command line arguments;

mysql_secure_installation

When run, the script prompts for specific action to take;

Sample command output;

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

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
haven't set the root password yet, 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 the root password? [Y/n] n
 ... skipping.

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!

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!

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!

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.

Thanks for using MariaDB!

Logging in to MariaDB

When installed, “root@localhost user is created with the ability to use two authentication plugins.

  • First, it is configured to try to use the unix_socket authentication plugin. This allows the the root@localhost user to login without a password via the local Unix socket file defined by the socket system variable, as long as the login is attempted from a process owned by the operating system root user account.

As a root user, you can login by running either of the commands below;

mysql
mysql -u root
  • Second, if authentication fails with the unix_socket authentication plugin, then it is configured to try to use the mysql_native_password authentication plugin. However, an invalid password is initially set, so in order to authenticate this way, a password must be set with SET PASSWORD“.
  • Note: If you provide a password while attempting to log into the server as an account that doesn’t require a password, then MariaDB server will simply ignore the password.

To enable password based authentication i.e use the mysql_native_password authentication:

Login to MariaDB;

mysql

Update the password;

ALTER USER root@localhost IDENTIFIED BY 'hacker';

If you exit and try passwordless authentication, you will get permission denied;

mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

And that is it on how to install MariaDB 10.7 on Debian 11/Debian 10.

Other tutorials:

Install MariaDB 10.6 on Debian 11

Install LEMP Stack on Debian 11

Install LAMP Stack on Debian 11

Founder of itnixpro.com|Linux Engineer|Author at Itnixpro.com

Leave a Comment