How to Install MariaDB on Ubuntu 20.04

How to Install MariaDB on Ubuntu 20.04

MariaDB is an open-source relational database management system. Originally designed as a replacement for backward-compatible binary MySQL backward.

MariaDB was developed and managed by the original MySQL developer and by the open-source community.

This guide explains how to install and secure MariaDB on Ubuntu 20.04.


We assume that you have administrative access to the Ubuntu server, either as root or as a user with sudo permission.

Install MariaDB on Ubuntu

At the time of writing this article, the latest version of MariaDB available in the Ubuntu repository is version 10.3. To install it run the following command:

sudo apt update sudo apt install mariadb-server

After the installation is complete, the MariaDB service will start automatically. To verify that the database server is running, type:

sudo systemctl status mariadb

The output will indicate that the service is activated and running:

Output :


Securing MariaDB

The MariaDB server package comes with a script called mysql_secure_installation which allows you to easily increase the security of the database server.

Run the script without arguments:

sudo mysql_secure_installation

The script will ask you to enter the root password:

Output :

Enter current password for root (enter for none):

Since you haven’t set a root password, just press “Enter” here.

At the next prompt, you will be asked to set a password for the MySQL root user:

Output :

Set root password? [Y/n] n

Type n. On Ubuntu, the MariaDB root user is authenticated by the auth_socket plugin by default. This plugin works by checking whether the local system user running the client program matches the specified MariaDB username.

Next, you will be asked to delete anonymous users, restrict root user access to the local machine, delete the test database, and load the privilege table again. You must answer Y for all questions:

Output :

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

Log in as root

To interact with the MariaDB server from the command line, use the mysql client utility or the alias mariadb. This tool is installed as a dependency from the MariaDB server package.

The auth_socket plugin authenticates users who are connected from localhost via a Unix socket file. This means you cannot authenticate as root by providing a password.

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

sudo mysql

You will be presented with the MariaDB shell, as shown below:

Output :

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 61
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> Bye

If you want to log in to your MariaDB server as root using an external program like phpMyAdmin, you have two options.

The first is to change the authentication method from auth_socket to mysql_native_password. You can do this by running the following command:

Maria DB-> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';FLUSH PRIVILEGES;

Second, the recommended option is to create a new dedicated administrative user with access to all databases:

GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';

You can give whatever administrative username you want, but make sure you use a strong password.


We have shown you how to install MariaDB on Ubuntu 20.04. Now that your database server is up and running, your next step is to learn how to manage MariaDB user accounts and user databases.

If you have questions or feedback, don’t hesitate to leave a comment.

Related posts

How to Set Up Automatic Kernel Updates on Linux


How to Set Up WireGuard VPN Server and Client on Ubuntu 20.04


How to Install Postman on Ubuntu 20.04


How to Install TensorFlow on CentOS


How to Change SFTP Port


How to install Lightworks on Ubuntu


How to Install Sublime Text 3 on Ubuntu 20.04


How to Manage Startup Programs on Ubuntu Linux


How to Install Docker on Ubuntu 20.04