MariaDB is an open source, multi-threaded relational database management system, backward compatible replacement for MySQL. It is maintained and developed by the MariaDB Foundation including some of the original developers of the MySQL.

In this tutorial we will show you two different methods on how to install MariaDB on your Ubuntu 18.04 machine. The first method describe the steps necessary to install MariaDB from the Ubuntu repositories while the second one will show you how to install the latest version of MariaDB from the official MariaDB repositories.

Generally, it is recommended to use the first method and install MariaDB packages provided by Ubuntu.

Installing MariaDB on Ubuntu 18.04 from MariaDB Repositories

At the time of writing of this article the latest version of MariaDB available from the official MariaDB repositories is MariaDB version 10.3. Before continuing with the next step you should visit the MariaDB Repository page and check if there is a new version available.

To install the latest stable version of MariaDB on your Ubuntu 18.04 from the MariaDB repositories, follow these steps:

Enable the MariaDB repository.

First add the MariaDB GPG key to your system using the following command:

Securing MariaDB

Run the mysql_secure_installation command to improve the security of the MariaDB installation:

sudo mysql_secure_installation

The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine and remove the test database. At the end the script will reload the privilege tables ensuring that all changes take effect immediately.

All steps are explained in detail and it is recommended to answer “Y” (yes) to all questions.

Connect to MariaDB from the command line

To connect to the MariaDB server through the terminal we can use the MariaDB client.

To log in to the MariaDB server as the root user type:

mysql -u root -p

You will be prompted to enter the root password you have previously set when the mysql_secure_installation script was run.

Once you enter the password you will be presented with the MariaDB shell as shown below: