To install MariaDB on Ubuntu 20.04, simply follow these steps:

  1. Update the system
  2. Initiate the in­stall­a­tion
  3. Customise the security script
  4. Create password-protected admin user (optional)
  5. Check the in­stall­a­tion

In the following sections, we will guide you step by step through the in­stall­a­tion.

MariaDB as part of the LAMP stack

MariaDB has es­tab­lished a notable lead over MySQL and is thus preferred by many users as their SQL server of choice. This fork of MySQL is regarded as extremely robust, highly flexible, and boasts a strong security ar­chi­tec­ture. MariaDB can be seam­lessly in­teg­rated into the LAMP stack (Linux, Apache, MySQL, and PHP, Python, or Perl) for Ubuntu as a drop-in re­place­ment without any modi­fic­a­tions or issues. In this guide, we provide step-by-step in­struc­tions on how to install and configure MariaDB on Ubuntu 20.04.

Tip

If you are using a newer version of the Linux dis­tri­bu­tion, you will also find detailed in­struc­tions for in­stalling MariaDB on Ubuntu 22.04 in our Digital Guide.

The re­quire­ments

Only a few re­quire­ments need to be met if you want to install MariaDB on Ubuntu. Before the actual process, you should make sure you have a server that is equipped with the Linux system (in this case version 20.04). To do this, an ad­min­is­trat­ive non-root user must be set up. The best possible way to secure the in­stall­a­tion is with a suitable firewall.

Compute Engine
The ideal IaaS for your workload
  • Cost-effective vCPUs and powerful dedicated cores
  • Flex­ib­il­ity with no minimum contract
  • 24/7 expert support included

Update your system

Before you install MariaDB on Ubuntu 20.04, it makes sense to update the system to the latest version. Use the cor­res­pond­ing apt commands to update the package index and ensure that all files and de­pend­en­cies are up to date. This is for security reasons so that you can work with a bug-free server. The cor­res­pond­ing commands are as follows:

sudo apt update
sudo apt upgrade
bash

Install MariaDB on Ubuntu 20.04

If your system including all packages has been suc­cess­fully updated, you can start in­stalling MariaDB on Ubuntu 20.04. Use the following command to unpack the packages of the database man­age­ment system that are already included in the Ubuntu re­pos­it­ory:

sudo apt install mariadb-server
bash

Only the in­stall­a­tion is performed in this step. Important security measures and con­fig­ur­a­tions will be taken care of in the following step.

Configure the security script

MariaDB includes its own security script for this purpose. This script allows you to modify various default settings, improving the ap­plic­a­tion’s security. You can execute the script with the following command:

sudo mariadb_secure_installation
bash

When you open the script, the first step will prompt you to enter your root password for the database. Since you haven’t set this up yet, just press [Enter] to bypass this step.

This will allow you to set up a new root password for the database in the next step. However, this can cause problems as the root of MariaDB is closely linked to system main­ten­ance. It is therefore advisable not to change the au­then­tic­a­tion options for the time being. Type in [N] and confirm with [Enter].

You can confirm the script’s ad­di­tion­al settings by pressing [Y] and [Enter]. Among other prompts, you will be asked if you wish to remove anonymous users and the test database. Fur­ther­more, remote root logins will be disabled. Finally, the script will ask if you want to apply all changes im­me­di­ately.

Op­tion­ally create a password-protected admin

The next step is optional, but as you have not set up a password for the root user, it is still very useful. If you set up an ad­di­tion­al ad­min­is­trat­or and ensure it’s password-protected, you are prepared for all use cases. By default, the login is actually done with a unix_socket plugin and no password is required. However, this can lead to com­plic­a­tions as soon as external programs require ad­min­is­trat­ive rights. Therefore, as a pre­cau­tion, create an ad­di­tion­al account that has admin rights and password pro­tec­tion. To do this, first open the MariaDB command prompt:

sudo mariadb
bash

Next, create the new admin and set a password. Adjust the ‘username’ and ‘password’ place­hold­ers to suit your needs:

GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
bash

Then use FLUSH PRIVILEGES to apply the changes im­me­di­ately:

FLUSH PRIVILEGES;
bash

Then exit the MariaDB shell:

exit
bash

Check the status

After you’ve installed MariaDB on Ubuntu 20.04, you can check the status to see if it has worked. Here is how to do that:

sudo systemctl status mariadb
bash

MariaDB is executed auto­mat­ic­ally by default. If this is not the case, you can access the database using the following command:

sudo systemctl start mariadb
bash
Go to Main Menu