Install MariaDB on Ubuntu 20.04 LTS - Step by step process to do it ?

MariaDB is an open-source relational database management system, commonly used as an alternative for MySQL as the database portion of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack.

It is intended to be a drop-in replacement for MySQL.

In our previous posts, we have explained how to install MariaDB in Debian , Mint , and CentOS .

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform database management related queries.

In this context, we shall look into how to install MariaDB on Ubuntu 20.04.


How to install Mariadb on Ubuntu 20.04 ?

You can install MariaDB via different methods as shown below:

i. Via Ubuntu Repository

ii. Via MariaDB Repository

The first method installs the older version of MariaDB (10.3) through Ubuntu Repository while the latter installs the latest version of MariaDB (10.5) through MariaDB Repository.


1. Installing MariaDB on Ubuntu via Ubuntu Repository

To install MariaDB on Ubuntu, you need to have sudo privileges. MariaDB's version 10.3 is available in the official repositories of Ubuntu distribution. 

Therefore, you can easily install it via apt. 

Following are the steps for the installation of MariaDB on Ubuntu.


i. Update package index

In order to install MariaDB, first update the package index. 

To do so, open the Terminal through the Ctrl+Alt+T shortcut and then execute this command:

$ sudo apt update


ii. Install MariaDB

Then install MariaDB as follows:

$ sudo apt install mariadb-server

After running the installation command, the system will ask if you want to continue the installation by prompting you with the y/n option. Hit y to carry on the installation process.


iii. Verify Installation

Once the installation of MariaDB is completed, you can verify it as follows:

$ mariadb --version

This command will output the version of MariaDB on your system which verifies that MariaDB is successfully installed.


2. Installing MariaDB on Ubuntu via MariaDB Repository

MariaDB’s latest version 10.5 is available in the official MariaDB repository.

Therefore, in order to install it, you will have to first add the MariaDB repository to your apt sources and then install it. 

Below are the steps to install MariaDB 10.5 on Ubuntu.


i. Install Pre-requisites

Install software-properties-common package through the following command in Terminal:

$ sudo apt-get install software-properties-common


ii. Add repository key

Then run this command to add the GPG key used to sign the MariaDB package:

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


iii. Add MariaDB repository

Now add MariaDB repository to your apt sources using the following command:

$ sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirror.biznetgio.com/mariadb/repo/10.5/ubuntu focal main'


iv. Update package index

Then update the packages index to include the MariaDB repository. 

Use the following command to do so:

$ sudo apt update


v. Install MariaDB

Once the packages list is updated with the MariaDB repository, you can install MariaDB as follows:

$ sudo apt install mariadb-server

After running the installation command, the system will ask if you want to continue the installation by prompting you with the y/n option. 

Hit y to carry on the installation process.


vi. Verify Installation

Once the installation of MariaDB is completed, you can verify it as follows:

$ mariadb --version

This command will output the version of MariaDB on your system which verifies that MariaDB is successfully installed.


How to Secure MariaDB after Installation ?

After successfully installing MariaDB, you can secure MariaDB server. We will do this by running a script mysql_secure_installation available on the Linux system. 

This script allows you to configure passwords for root, disable root login remotely, remove root anonymous user accounts and test database, and so on.

To configure the security settings for MariaDB, run the script as follows:

$ sudo mysql_secure_installation

After running the above script, you will be prompted for the various questions. 

It will ask you to provide your root password for MariaDB. As we have not configured it yet, therefore press Enter

Then it will ask if you want to configure a root password, hit y, and then enter the password and confirm by re-entering it.

Then for all the subsequent questions, hit y .


How to Verify MariaDB Service ?

MariaDB service starts running automatically after the installation is completed. 

To verify if the MariaDB service is running fine without any issues, run the following command in Terminal:

$ sudo systemctl status mariadb

It is expected that MariaDB server is active and running.

If the MariaDB service does not run automatically, you can start it manually as follows:

$ sudo systemctl start mariadb


How to connect to MariaDB ?

Now try connecting to the MariaDB server as a root user. 

Run the following command to do so:

$ sudo mysql -u root -p

You will be prompted to enter the root for MariaDB password (that you have configured earlier). 

Once you entered the password, you will be connected to the MariaDB database.


How to uninstall MariaDB from Ubuntu ?

In case, you want to completely remove MariaDB from your system, you can do so easily using the following command in Terminal:

$ sudo apt-get purge mariadb-server

After running the purge command, the system will ask if you want to continue the process by providing you with the y/n option. 

Hit y to carry on the uninstallation process.


Then remove the packages that were automatically installed to satisfy dependencies for MariaDB. 

Run the following command to do so:

$ sudo apt autoremove


[Need urgent assistance to configure MariaDB on your #Linux Server? We are available to help you today. ]

This article covers how to install MariaDB on Ubuntu 20.04 LTS system. Also you will learn how to secure it by configuring some security options and then, in the end, we have tested the connection to MariaDB. The #Ubuntu server should have a non-root administrative user and a firewall configured with UFW.

By following the above simple steps, you can easily setup MariaDB on your ubuntu system. 

For more information, visit MariaDB's official documentation .

MariaDB is one of the most widely used and open-source database management systems. 

MariaDB is considered as a replacement for #MySQL and has much more features and capabilities that you cannot find in MySQL.


To install #MariaDB on Debian:

1. Update your package index using apt;

$ sudo apt update

2. Install the mariadb-server package using apt. The package also pulls in related tools to interact with MariaDB;

$ sudo apt install mariadb-server

3. Run the included mysql_secure_installation security script to restrict access to the server;

$ sudo mysql_secure_installation

Related Posts