How To Install MariaDB 10.6 on Debian 11/10/9

Posted on 292 views

MariaDB is a popular open source relational databases, developed by MySQL developers. Unlike MySQL, MariaDB was meant to be totally free for use. Its development puts a lot of considerations on performance and stability. MariaDB is also mostly preferred for being robust and scalable with new storage engines. MariaDB 10.6 also comes with a number of improvements from version 10.5 and some additional features. mariaDB has different tools and plugins that make it widely applicable. It is the default database in most Linux distributions.

This guide presents a step-by-step installation of MariaDB 10.6 on Debian 11/10/9 from MariaDB APT repository.

MariaDB 10.6 is the current stable version of MariaDB and comes with a number of improvements and new features as discussed below:

New Features of MariaDB 10.6

  • Ignored Indexes – These are indexes that are visible and maintained but not used by the optimizer
  • sys schema supported– This is a “system” database containing views and procedures for investigating performance problems.
  • SKIP LOCKED – Locked tables are skipped from being updated or selected.
  • JSON_TABLE() – can create a JSON table that can be used as a subquery from a JSON document.
  • OFFSET…FETCH…[WITH TIES] – WITH TIES is an optional clause that adds extra functionality. Example as used
  • Oracle compatibility – There are ongoing works in making MariaDB compatible with OracleDB with some Oracle Syntaxes and functions already added.

Improvements in MariaDB 10.6

Some of the improvements on MariaDB 10.6 from its predecessors include:

  • Atomic DDL – CREATE, ALTER, DROP and RENAME are atomic and crash safe. If MariaDB server crashes while processing any of these operations, the change will either e done completely or not done at all.
  • InnoDB improvements – First insert to an empty table is faster. Also writes to temporary tables are avoided.Faster implicit and explicit temporary tables.
  • Improvements in Galera. Ability to enable encrypted connections between two nodes without downtime. Also added flags to specify if galera controversial compatible features should be enabled.
  • Clean up to remove unsupported features such as TukoDB Engine, Cassandra Engine, some InnoDB variables and some innodb_checksum_algorithm.

Installing MariaDB 10.6 on Debian 11/10/9

Follow the next steps to install MariaDB 10.6 on your latest Debian Servers

Step 1: System Upgrade

It is always recommend to have the latest system packages before installation to avoid dependency issues. Run the below commands:

sudo apt update
sudo apt upgrade
sudo reboot

Step 2: Install required Packages

Next, install necessary packages as below:

sudo apt-get install curl software-properties-common dirmngr

Step 3: Add MariaDB Signing Key and APT Repository

Run the below commands respectively to import MariaDB signing key and add MariaDB APT repository

For Debian 11 (Bullseye):

curl -LsS -O
sudo bash mariadb_repo_setup --os-type=debian  --os-version=buster --mariadb-server-version=10.6
sudo dpkg -i libreadline5_5.2+dfsg-3+b13_amd64.deb

For Debian 10 (Buster):

curl -LsS -O
sudo bash mariadb_repo_setup --mariadb-server-version=10.6

For Debian 9 “Stretch”

curl -LsS -O
sudo bash mariadb_repo_setup --mariadb-server-version=10.6

Step 4: Install MariaDB on Debian 11/10/9

Next, update packages and install MariaDB server

sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

Proceed to install MariaDB packages and all its dependencies:

The following NEW packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libclone-perl libdaxctl1 libdbd-mariadb-perl libdbi-perl libencode-locale-perl libfcgi-bin libfcgi-perl
  libfcgi0ldbl libgdbm-compat4 libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmariadb3 libmpfr6 libndctl6 libperl5.32 libpmem1 libsigsegv2 libterm-readkey-perl libtimedate-perl liburi-perl lsof mariadb-client
  mariadb-client-10.6 mariadb-client-core-10.6 mariadb-common mariadb-server mariadb-server-10.6 mariadb-server-core-10.6 mysql-common perl perl-modules-5.32
0 upgraded, 41 newly installed, 0 to remove and 0 not upgraded.
Need to get 37.5 MB of archives.
After this operation, 265 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Step 5: Start and Enable MariaDB

Now run the following commands to start MariaDB and enable it to automatically start on system reboot

sudo systemctl start mariadb
sudo systemctl enable mariadb

Confirm that MariaDB is running

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 10.6.3 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor pres>
    Drop-In: /etc/systemd/system/mariadb.service.d
     Active: active (running) since Wed 2021-07-28 23:03:14 EAT; 8min ago
       Docs: man:mariadbd(8)

Step 6: Secure MariaDB Installation

Once MariaDB is successfully installed, proceed to secure it as below:

$ sudo mysql_secure_installation 


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] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!

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

Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

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!

Step 7: Check MariaDB Version

To check MariaDB version, we need to login to MariaDB as below. Use -p if you have set the root password.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.6.3-MariaDB-1:10.6.3+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)]>

Then run the following MySQL command to check MariaDB version

MariaDB [(none)]> SELECT VERSION();
| VERSION()                              |
| 10.6.4-MariaDB-1:10.6.4+maria~bullseye |
1 row in set (0.000 sec)

MariaDB [(none)]>

Step 8: MariaDB Basic Commands

To get started with basic commands, we can check to create a database, users and tables.

MariaDB Create Database

To create a database in MariaDB, login as shown above and run the below command.

#Create a new database
Query OK, 1 row affected (0.000 sec)

#If the database with the same exists
ERROR 1007 (HY000): Can't create database 'testdb'; database exists

#Create a database if already exits
Query OK, 2 rows affected (0.009 sec)

#First check if a database exists 
Query OK, 1 row affected, 1 warning (0.000 sec)

# Check Databases MariaDB

MariaDB add User and Grant Privileges

To create a user and grant privileges;

#Create user mariadb
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant all privileges to the user
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant privileges to a specific database
GRANT ALL PRIVILEGES ON 'DB1'.* TO 'user1'@'localhost';

#Remember to refresh the privileges
FLUSH privileges;

#To check user grants in MariaDB
SHOW GRANTS FOR 'myuser'@'locahost';

Create a Table and Add Data MariaDB

Once you have created a database, you can create table and add data into it

CREATE TABLE employees (id INT, name VARCHAR(20), email VARCHAR(20));
INSERT INTO employees (id,name,email) VALUES(01,"lorna","[email protected]")

MariaDB Clean up

To completely remove MariaDB, run the following commands.

sudo apt purge mariadb-server
sudo rm -rf /var/lib/mysql/

That’s it. You have successfully installed MariaDB 10.6 on Debian 11/10/9. It is a simple and straightforward installation. I hope the guide has been helpful.

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.