How to Install MariaDB on Ubuntu 20.04 LTS

install Mariadb on Ubuntu 20.04

MariaDB is a free and open-source relational database management system (RDMS) which is a fork and drop-in replacement of MySQL. It is developed and maintained by the community and the set of developers who once worked on MySQL before it was acquired by Oracle.

There are 2 ways of installing MariaDB on Ubuntu 20.04. You can directly install it using the APT package manager, and this is usually the fastest way of doing this. However, this doesn't give you the latest version of MariaDB. The second method involves manually adding the GPG key and MariaDB repository. With this method, you get the latest version which, by the time of writing this guide, is MariaDB version 10.5.

Method 1. Install MariaDB on Ubuntu 20.04

MariaDB is available in the default APT repository of Ubuntu 20.04. You can simply install Mariadb using apt.

First update package list with the latest available versions, type:

$ sudo apt update

Now, Install the Mariadb package:

$ sudo apt install mariadb-server
Install MariaDB server on Ubuntu
Install MariaDB server on Ubuntu using APT

MariaDB server starts automatically upon completion of the installation. You can verify this by running:

$ sudo systemctl status mariadb
mariadb service status
Check the status of mariadb service

To log in as the root user, run the command:

$ sudo mysql
Log in to MySQL database
Log in to MySQL database

To verify the Mariadb version installed, invoke the following command on the MariaDB shell.

SELECT VERSION();
Show version of MariaDB
Show version of MariaDB

You can now create user account and manage MariaDB database.

Method 2.  Install MariaDB on Ubuntu using MariaDB Repo

This method installs the latest version on MariaDB. Here we will use MariaDB apt repository.

First Import the GPG key as shown:

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

Next, add the MariaDB APT repository as shown.

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

Thereafter, update the package lists to sync with the added repository.

$ sudo apt update

Finally, install MariaDB by running the command:

$ sudo apt install mariadb-server mariadb-client
Install MariaDB-server MariaDB-client
Install MariaDB-server MariaDB-client

MariaDB should run automatically once the installation is complete. As before, you can verify this by executing:

$ sudo systemctl status mariadb

To verify the version, log in to MariaDB as root.

$ sudo mysql

Next, run the command below in the MariaDB syntax:

SELCT VERSION();
Check version of latest MariaDB version
MariaDB 10.5.8 version installed

Conclusion

In this guide, we took you through 2 ways of installing the MariaDB database server. It's our hope you can comfortably install MariaDB on Ubuntu 20.04 using the just-discussed methods.

Leave a Comment