How to install MariaDB Server on Ubuntu 20.04 (Focal Fossa)

MariaDB is the most powerful and widely used relational database management system developed by the MariaDB Foundation. We have many articles about installing MariaDB on various Linux distributions. This guide will focus on the process of installing MariaDB on Ubuntu 20.04 (Focal Fossa).

For novice MariaDB, it is a branch of the MySQL database system developed by the community. It was originally designed to be free and open source without any compromises in terms of speed, stability, and scalability. Most Linux distributions will provide MariaDB in their upstream repositories for quick installation using the default OS package manager.

Install MariaDB Server on Ubuntu 20.04 (Focal Fossa)

We always start the installation by making sure the system is updated. This can be achieved by running the following command:

sudo apt update
sudo apt -y upgrade

After the system is updated, use the following command to install MariaDB Server on Ubuntu 20.04 (Focal Fossa).

sudo apt install software-properties-common mariadb-server mariadb-client

Confirm that the service is started.

$ systemctl status mariadb
● mariadb.service - MariaDB 10.3.19 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2019-12-23 18:31:46 UTC; 46s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 2144 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 614)
     Memory: 65.8M
     CGroup: /system.slice/mariadb.service
             └─2144 /usr/sbin/mysqld

Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: Running 'mysqlcheck' with connection arguments: --socket='/var/run/mysqld/mysqld.sock' --host='>
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: # Connecting to localhost...
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: # Disconnecting from localhost...
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: Processing databases
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: information_schema
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: performance_schema
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: OK
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2244]: Checking for insecure root accounts.
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2248]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

By default, you should be able to access the mysql command line as the root user without prompting you for a password. Make sure we hardened the MariaDB server and set the root password.

$ 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
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 ensures that nobody can log into the MariaDB
root user without the proper authorisation.

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

Confirm that MariaDB Server is installed on Ubuntu 20.04 (Focal Fossa)

Let’s confirm we have MariaDB server installed on Ubuntu 20.04

$ mysql -V
mysql  Ver 15.1 Distrib 10.3.19-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Create a test database.

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

MariaDB [(none)]> DROP  DATABASE testdb;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> QUIT
Bye

Enjoy using MariaDB database server on Ubuntu 20.04 Focal Fossa Linux. For other systems, check:

Install MariaDB on Fedora

How to install MariaDB on Debian 10 (Buster)

How to install MariaDB on CentOS 7

How to install MariaDB on CentOS 8 / RHEL 8

Sidebar