MariaDB is a free and open-source relational database system, that has come to be one of the most popular and widely used in the world.

Development is lead by some of the original developers of MySQL, who forked MariaDB from MySQL in 2009, due to concerns over MySQL’s acquisition by Oracle Corporation.

MariaDB is currently developed and maintained by the MariaDB Foundation and is a drop-in replacement for MySQL. Prominent users of MariaDB include Mozilla, Google and the Wikimedia Foundation, who have switched to it since 2013.

In this tutorial we’ll install MariaDB on an Ubuntu 18.04 machine using two methods:

  1. The first installation method will be installing MariaDB from the Ubuntu repositories.
  2. The second method will be installing MariaDB from the official MariaDB repositories.


  • We recommend that you use a non-root sudo user when making major changes to your system. If you don’t have one set up, you can follow our tutorial on creating a sudo user on Ubuntu.

Looking for a new Laptop?

Laptops with Thunderbolt 3 are future proof!

Method 1 – Installing MariaDB from the Ubuntu Repositories

To install MariaDB from the Ubuntu Repositories we’ll just have to update our package index, and then install mariadb-server To do so, run the following commands:

Now that MariaDB is installed, we can check the status to be sure the installation was successful.

The output should look something like this.

If the terminal is stuck on the output of status, you may have to press q, for quit, and everything should return back to normal.

You can also check the version by running:


MariaDB is now installed, but the configuration is not finished. Please refer to Secure MariaDB to finish the configuration.

Method 2 – Installing MariaDB from the MariaDB Repositories

To install MariaDB from the Official Mirror, follow these steps:

  1. Install software-properties-common so that we may use the add-apt-repository later on, to add the MariaDB Repository
  2. Before adding the repository, add the MariaDB GPG key to our system:
  3. Add the Official MariaDB Repository for Ubuntu 18.04 to our system:
  4. Update your package index to ensure we’ll install the latest packages:
  5. Now that the official repository is added and we’ve got our package list up-to-date, we can install MariaDB:
  6. Check the status of the MariaDB service, to make sure the installation went well:
  7. Check the MariaDB version by running:

MariaDB’s configuration isn’t finished yet, however.

Securing MariaDB

To secure the installation, MariaDB comes with a script to help adjust some insecure defaults. Start the script by running:

First, it will ask you if you’d like to enable VALIDATE PASSWORD PLUGIN.

If you enable this, then depending on the type of validation you choose (LOW, MEDIUM or STRONG), MySQL will return errors if your password does not meet the specified criteria for the policy you’ve chosen. This may conflict with other software packages, so it is up to you to decide. In our tutorial, we will choose Y.

We’ll choose 1. We recommend you choose what level of complexity you prefer between MEDIUM and STRONG.

New password: Enter password
Re-enter new password: Repeat password

You’ll also be prompted to answer some questions to remove/keep some defaults. We recommend you answer them as follows:

Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

To make sure MySQL is properly installed, let’s test it out by running the following command, and entering the password you just created at the prompt:

To exit just run:

Connect to MariaDB

MariaDB should now be installed and configured. You can log into it using the command line to test that the install was successful.

To do this, we’ll run the following command, and enter the password we set for MariaDB at the prompt:

After you’ve entered the password correctly, you should be greeted by the MariaDB shell.

That’s it. You can start using MariaDB.


Well done. You should now have MariaDB installed on your Ubuntu 18.04 machine. If you’ve encountered any issues, be sure to leave us a comment and we’ll get back to you as soon as possible.

Should you need to manage MariaDB via a web interface, you can follow our tutorial on installing phpMyAdmin on Ubuntu 18.04


Tech Support

Leave a Comment


Enter your email below to get 20% OFF on any of our Linux VPS plans and receive weekly deals on our services!