Back to Article List

How to install MariaDB on Ubuntu 20.04

MariaDB logo
mariadb.org

MariaDB is a database management system commonly used as a drop-in replacement for MySQL. A LAMP (Linux, Apache, MySQL, PHP) stack normally includes MySQL, but you can use MariaDB instead, depending on your requirements.

In this guide, I will explain how to set up MariaDB on Ubuntu 20.04 using a non-root admin user and a UFW (Uncomplicated Firewall) setup. You can find more information on setting up UFW in my guide, "How to install and configure UFW in Ubuntu 20.04".

Installing MariaDB on Ubuntu 20.04

Step 1: Install MariaDB

As always, any good install starts with a good update:

sudo apt update

Once the update has finished, install the default MariaDB package:

sudo apt install mariadb-server

Now, let's check the status of MariaDB to verify that it's running:

sudo systemctl status mariadb

This outputs the status of the mariadb.service. You should see:

Active: active (running) since (time the process started)

If for some reason the service did not start, you can start it manually with:

sudo systemctl start mariadb

Step 2: Configure MariaDB

Now that MariaDB is installed and running, we need to configure its security settings. Run the included security script, which will ask you a series of questions:

sudo mysql_secure_installation

First, you will be asked for the current root password. Since this is a fresh MariaDB install, there isn't one yet, so simply press Enter to leave the field blank and continue:

Enter current password for root (enter for none):

Next, you will be asked whether you want to set a root password:

Set root password? [Y/n]

You can set a password if you like, but keep in mind that on Ubuntu, the MariaDB root account is closely tied to automated system maintenance and, by default, authenticates through the system's root user rather than a password. Changing the authentication method for that account can cause problems, so on Ubuntu it's usually best to answer n here.

After that, the script asks a few more questions: whether to remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables. For a secure setup, answer Y to all of them.

To confirm everything works, log in to MariaDB from your admin user:

sudo mariadb

Type exit to leave the MariaDB prompt. That's it: your new MariaDB system is up and running!


If you have questions about any of our services, please contact us via email at [email protected] or by using our live chat at spinservers.com.

Spin Servers is a US-based provider of dedicated servers & affordable private cloud solutions. Our motto is to let you "spin up servers" fast, seamlessly, and affordably.