How to install MariaDB 10.6 on Ubuntu 20.04|18.04

MariaDB is one of the most commonly used open source relational databases. It is developed by MySQL developers, but unlike MySQL, it is completely free. MariaDB’s development focuses on stability and performance. Another reason for MariaDB’s popularity is that it is powerful and extensible, is a new storage engine, and comes with various tools and plug-ins that make it widely applicable. It is the default database in most Linux distributions.

In this guide, we will learn how to install MariaDB 10.6 on Ubuntu 20.04 and Ubuntu 18.04 from MariaDB APT repository.

Features of MariaDB 10.6

MariaDB 10.6 is the current stable version of MariaDB with many new features, as described below:

  • Ignored indexes-these are indexes that are visible and maintained but not used by the optimizer
  • Support for sys mode-this is a “system” database that contains views and procedures for investigating performance issues.
  • SKIP LOCKED-The locked table is skipped update or selection.
  • JSON_TABLE() – You can create a JSON table that can be used as a subquery for JSON documents.
  • Offset…retrieve…[WITH TIES] – WITH TIES is an optional clause, which adds additional functions.Example of use
  • Oracle Compatibility-Work in progress is to make MariaDB compatible with OracleDB, and some Oracle syntax and features have been added.

Some improvements in MariaDB 10.6 compared to its predecessor include:

  • Atomic DDL-CREATE, ALTER, DROP and RENAME are atomic and safe. If the MariaDB server crashes while processing any of these operations, the changes are either completely completed or not at all.
  • InnoDB improvements-inserting an empty table for the first time is faster. Also avoid writing to temporary tables. Faster implicit and explicit temporary tables.
  • Galera’s improvements. Ability to enable encrypted connections between two nodes without downtime. A flag has also been added to specify whether galera’s controversial compatibility features should be enabled.
  • Clean up to remove unsupported features, such as TukoDB engine, Cassandra engine, some InnoDB variables, and some innodb_checksum_algorithm.

The first step: system upgrade

As usual, we first run a system upgrade to ensure that we perform our installation on the latest package. After the update, restart the server.

                        sudo apt update
sudo apt upgrade -y
sudo reboot

Step 2: Install the required packages

Next, we have to install the software-properties-common package

                        sudo apt install software-properties-common -y

Step 3: Import MariaDB GPG key and add MariaDB APT repository

Using the following commands respectively, we will add the MariaDB signing key and add the MariaDB APT repository:

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

You will get an output that looks like this:

                        [info] Checking for script prerequisites.
[info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
[info] Adding trusted package signing keys...
[info] Running apt-get update...
[info] Done adding trusted package signing keys

Step 4: Install MariaDB 10.6 on Ubuntu 20.04|18.04

After adding MariaDB key and APT repository, update the package and proceed to install MariaDB 10.6 on Ubuntu 20.04|18.04:

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

Step 5: Secure MariaDB installation

After installing MariaDB, run the following MySQL script to protect MariaDB


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] 
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] 
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] 
 ... 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] 
 ... 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] 
 - 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] 
 ... 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 6: Confirm Mariadb status

The MariaDB server should start automatically. The check status is as follows:

                        $ systemctl status mariadb
● mariadb.service - MariaDB 10.6.4 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
   Active: active (running) since Tue 2021-10-19 11:37:25 UTC; 9s ago
     Docs: man:mariadbd(8)
 Main PID: 3023 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 14 (limit: 4703)
   CGroup: /system.slice/mariadb.service
           └─3023 /usr/sbin/mariadbd

Oct 19 11:37:29 ubuntu /etc/mysql/
                        -start[3046]: performance_schema
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: sys
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: Phase 6/7: Checking and upgrading tables
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: Processing databases
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: information_schema
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: performance_schema
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: sys
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: sys.sys_config                                     OK
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Oct 19 11:37:29 ubuntu /etc/mysql/debian-start[3046]: OK
[email protected]:~#

Step 7: Enable MariaDB to start when the server restarts

Run the following command to make MariaDB start automatically when the server restarts

                        sudo systemctl enable mariadb

Step 8: Check MariaDB version

To confirm the installed version, we need to log in to MySQL first, as shown below.

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

Now run the following command to check MariaDB version

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

MariaDB [(none)]> QUIT

Step 9: Basic use of MariaDB

Next, we will see some basic usages of MariaDB Dababase, such as creating databases, users, etc.

MariaDB create database

As shown above, MariaDB uses MySQL syntax. To create a database, you first need to log in to mariadb as shown above, and then run the following command to create the database.

                          #Create a new database

                        MariaDB [(none)]> 
                          CREATE DATABASE db1;
Query OK, 1 row affected (0.000 sec)

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

#Create a database if already exits
MariaDB [(none)]>  
                          CREATE OR REPLACE DATABASE db1;
Query OK, 2 rows affected (0.009 sec)

#First check if a database exists 
MariaDB [(none)]> C
                          REATE DATABASE IF NOT EXISTS db1;
Query OK, 1 row affected, 1 warning (0.000 sec)

# Check Databases MariaDB
MariaDB [(none)]>  
                          SHOW DATABASES;

MariaDB add users and grant permissions

Create users and grant permissions;

                        #Create user mariadb
MariaDB [(none)]> 
                          CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant all privileges to the user
MariaDB [(none)]> 
                          GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant privileges to a specific database
MariaDB [(none)]> 
                          GRANT ALL PRIVILEGES ON 'DB1'.* TO 'user1'@'localhost';

#Remember to refresh the privileges
MariaDB [(none)]>
                           FLUSH privileges;

#To check user grants in MariaDB
MariaDB [(none)]> 
                          SHOW GRANTS FOR 'myuser'@'localhost';

Create table and add data MariaDB

After creating the database, you can create tables and add data to it

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

MariaDB cleanup

If you want to clean up the MariaDB installation completely, you can delete and reinstall it.

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

This is how to install MariaDB 10.6 on Ubuntu 20.04 and Ubuntu 18.04. This is a short and simple installation, I hope this guide is helpful to you.

Udemy video course for learning MySQL / MariaDB database:

Check out more educational guides below:

  • Install MariaDB 10.5 on Ubuntu 20.04
  • Install MariaDB 10.5 on Kali Linux
  • Install MariaDB 10.6 on CentOS 8|RHEL 8
  • Install MariaDB 10.5 on CentOS 8|CentOS 7
  • Use ProxySQL to install MariaDB Galera cluster on Ubuntu 20.04