How to install MariaDB in Ubuntu?

MariaDB is an open-source, community-developed relational database management system. It maintains high compatibility with MySQL and is intended to be a drop-in replacement for it. Some of the original developers of MySQL are developers of this project.

In this article, I will discuss how to install and use MariaDB in Ubuntu.


You should have access to a user account with superuser privileges.

How to install MariaDB in Ubuntu

There are multiple ways to install MariaDB in Ubuntu. You can use one of the given methods to install it on your system.

Method 1: Installing MariaDB from Ubuntu repository

MariaDB is available in the official Ubuntu repository you can download and install from it. Before installing MariaDB on your system make sure the local package database is updated –

sudo apt update

Next, use the following command to install MariaDB in Ubuntu –

sudo apt install mariadb-server

If it asks for your confirmation type y and then press the Enter. This will start the installation process.

Once installation gets completed you can verify it by using.

mariadb --version

This will display the version of MariaDB installed on your system.

mariadb version

Method 2: Installing from official MariaDB repository

If you want to install it from the official repository of MariaDB then first install the required dependencies by using –

sudo apt-get install software-properties-common

Next, import the repository key –

sudo apt-key adv --fetch-keys ''

Add the MariaDB repository by using –

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] focal main'

Now refresh the package repository on your system –

sudo apt update

Finally use the following command to install the MariaDB on your system –

sudo apt install mariadb-server -y

Again you check the installed version of MariaDB on your system –

mariadb --version

Check the status of MariaDB database server

The MariaDB services will automatically get started on your system. You can check if MariaDB services running or not by using the given command.

sudo systemctl status mariadb

Now you will see the output as given in the image below.

status maria db server

Securing MariaDB database

You can run the mysql_secure_installation to secure MariaDB on your system. This is a security script that makes some less secure default options more secure for example the Validate Password Component is used to test the strength of the MySql password, you can disallow remote root login if you want.

Use the given command to run this script –

sudo mysql_secure_installation

This will prompt you to choose the options if you want to allow the option press y and enter for yes otherwise type n and then press enter for no. Meanwhile, you will be asked to set the MariaDB database root user password. Choose the strength 0 for low 1 for medium 3 for strong password and then enter the password for root.

Once everything gets completed you will see the All Done message.

Connect to MariaDB database

To connect to the MariaDB database open your terminal and type the following command.

sudo mysql -u root -p

Type the root user password and press Enter.

mariadb prompt

Once authentication gets completed. Your prompt will change to MariaDB shell. Now you can start executing MySQL commands for creating databases.


You can follow these instructions to install MariaDB on other Debian-based Linux distributions such as Linux Mint, Kali Linux, etc.

Now if you have a query then leave it in the comments below.

Leave a Comment