How To Install MariaDB on Ubuntu 20.04 [Quickstart]

Updated on March 18, 2022

Manager, Developer Education

How To Install MariaDB on Ubuntu 20.04 [Quickstart]

A previous version of this tutorial was written by Brian Boucheron


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.

This quickstart tutorial describes how to install MariaDB on an Ubuntu 20.04 server and set it up with a safe initial configuration. It will also cover how to set up an additional administrative account for password access.


To follow this tutorial, you will need a server running Ubuntu 20.04. This server should have a non-root administrative user and a firewall configured with UFW. Set this up by following our initial server setup guide for Ubuntu 20.04.

Step 1 — Installing MariaDB

Before you install MariaDB, update the package index on your server with apt:

  1. sudo apt update

Then install the package:

  1. sudo apt install mariadb-server

When installed from the default repositories, MariaDB will start running automatically. To test this, check its status.

  1. sudo systemctl status mariadb

You’ll receive output that is similar to the following:

● mariadb.service - MariaDB 10.3.22 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-05-12 13:38:18 UTC; 3min 55s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 25914 (mysqld) Status: "Taking your SQL requests now..." Tasks: 31 (limit: 2345) Memory: 65.6M CGroup: /system.slice/mariadb.service └─25914 /usr/sbin/mysqld . . .

If MariaDB isn’t running, you can start it with the command sudo systemctl start mariadb.

Step 2 — Configuring MariaDB

Run the security script that came installed with MariaDB. This will take you through a series of prompts where you can make some changes to your MariaDB installation’s security options:

  1. sudo mysql_secure_installation

The first prompt will ask you to enter the current database root password. Since you have not set one up yet, press ENTER to indicate “none”.

. . . Enter current password for root (enter for none):

The next prompt asks you whether you’d like to set up a database root password. On Ubuntu, the root account for MariaDB is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Type N and then press ENTER.

. . . Set root password? [Y/n] N

From there, you can press Y and then ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and then load these new rules.

Step 3 — (Optional) Creating an Administrative User that Employs Password Authentication

On Ubuntu systems running MariaDB 10.3, the root MariaDB user is set to authenticate using the unix_socket plugin by default rather than with a password. Because the server uses the root account for tasks like log rotation and starting and stopping the server, it is best not to change the root account’s authentication details. Instead, the package maintainers recommend creating a separate administrative account for password-based access.

To this end, open up the MariaDB prompt from your terminal:

  1. sudo mariadb

Then create a new user with root privileges and password-based access. Be sure to change the username and password to match your preferences:

  1. GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Flush the privileges to ensure that they are saved and available in the current session:


Following this, exit the MariaDB shell:

  1. exit

You can test out this new user with the mysqladmin tool, a client that lets you run administrative commands. The following mysqladmin command connects to MariaDB as the admin user and returns the version number after prompting for the user’s password:

  1. mysqladmin -u admin -p version

You will receive output similar to this:

mysqladmin Ver 9.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu on x86_64 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Server version 10.3.22-MariaDB-1ubuntu1 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 4 min 49 sec Threads: 7 Questions: 467 Slow queries: 0 Opens: 177 Flush tables: 1 Open tables: 31 Queries per second avg: 1.615


In this guide you installed the MariaDB relational database management system, and secured it using the mysql_secure_installation script that it came installed with. You also had the option to create a new administrative user that uses password authentication.

Now that you have a running and secure MariaDB server, here some examples of next steps that you can take to work with the server:

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Manager, Developer Education

Technical Writer @ DigitalOcean

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
Leave a comment

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel