Install MariaDB 10.5 on Ubuntu 20.04 LTS (Focal Fossa)

This article helps you install MariaDB 10.5 on a Ubuntu Server 20.04 LTS. MariaDB is a fork of the MySQL database management system. The RDBMS offers data processing capabilities for both small and enterprise tasks.

This DBMS is an improved version of MySQL. It comes with numerous inbuilt powerful features and many usabilities, security and performance improvements that you cannot find in MySQL.

This article assumes a clean installation of Ubuntu 20.04 LTS (Focal Fossa).

Update your system packages and dependencies.

Run the following commands to get information on the newest versions of packages and their dependencies and update them.

larry@server-1:~$ sudo apt update -y && sudo apt upgrade -y

Install the software-properties-common if missing.

sudo apt-get install software-properties-common -y

Import the MariaDB Apt Repository Key

To install MariaDB 10.5, you need to add the MariaDB repository on to the system. Import the MariaDB Apt repository key using the following command:

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

// Output

Executing: /tmp/apt-key-gpghome.FagkhIa3Hq/gpg.1.sh --fetch-keys https://mariadb.org/mariadb_release_signing_key.asc
gpg: requesting key from 'https://mariadb.org/mariadb_release_signing_key.asc'
gpg: key F1656F24C74CD1D8: public key "MariaDB Signing Key <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Add the MariaDB Apt Repository

sudo add-apt-repository 'deb [arch=amd64] http://mariadb.mirror.globo.tech/repo/10.5/ubuntu focal main'

// Output

Hit:1 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1026 kB]
Get:6 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [781 kB]
Get:7 http://mariadb.mirror.globo.tech/repo/10.5/ubuntu focal InRelease [6264 B]
Get:8 http://mariadb.mirror.globo.tech/repo/10.5/ubuntu focal/main amd64 Packages [17.4 kB]
Fetched 2159 kB in 1s (3101 kB/s)
Reading package lists... Done

Install MariaDB Server 10.5

Run the apt update , install MariaDB server and client package using the following commands:

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

// Output - Should install with no errors

Secure your MariaDB Server

After successful install, we will use the mysql_secure_installation command that helps us to improve the security of MariaDB installation. If you were not prompted for a password during MariaDB installation then you password is blank, just press enter for none:

sudo mysql_secure_installation

// Output

larry@server-1:~$ sudo mysql_secure_installation

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

MariaDB will reload tables after the hardening script. Reloading the privilege tables will ensure that all changes will take effect immediately

Check the status of MariaDB 10.5

sudo systemctl status mysql

// Output

larry@server-1:~$ sudo systemctl status mysql
● mariadb.service - MariaDB 10.5.10 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 Thu 2021-06-10 16:27:06 UTC; 11min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 4689 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 4713)
     Memory: 70.1M
     CGroup: /system.slice/mariadb.service
             └─4689 /usr/sbin/mariadbd

Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: Processing databases
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: information_schema
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: mysql
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: performance_schema
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: Phase 6/7: Checking and upgrading tables
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: Processing databases
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: information_schema
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: performance_schema
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Jun 10 16:27:08 server-1 /etc/mysql/debian-start[4710]: OK

MariaDB is running and tables have been upgraded and flushed.

Test login to MariaDB shell using mysql command

Use your MariaDB password you set during hardening script above.

sudo mysql -u root -p

// Output

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.5.10-MariaDB-1:10.5.10+maria~focal mariadb.org 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)]>

Check and confirm the MariaDB 10.5 version.

// Query & Output

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

MariaDB [(none)]>

Your MariaDB is ready. Thank you