Simply follow these steps to install MariaDB on Ubuntu 22.04:

  1. Update the system
  2. Install the database
  3. Configure the security script
  4. Create ad­di­tion­al admin with password pro­tec­tion (optional)
  5. Test MariaDB

This article shows you the in­di­vid­ual steps that need to be carried out.

MariaDB as a drop-in re­place­ment for MySQL

The re­la­tion­al database man­age­ment system MariaDB was first published in 2009 as a fork of MySQL and is now con­sid­ered a strong al­ter­na­tive to this SQL server. Even in com­par­i­son with MySQL, the fork impresses with its high flex­i­bil­i­ty and excellent security ar­chi­tec­ture. As a drop-in re­place­ment for MySQL, MariaDB can be in­te­grat­ed directly into the LAMP stack (Linux, Apache, MySQL and PHP, Python or Perl) without any problems. The solution packages are now also supplied as standard in the Ubuntu repos­i­to­ry. Below we explain how to install MariaDB on Ubuntu 22.04.

Tip

If you want to use an older version of the Linux dis­tri­b­u­tion, you will also find detailed in­struc­tions for how to install MariaDB on Ubuntu 20.04 in our Digital Guide.

The necessary re­quire­ments

If you want to install MariaDB on Ubuntu 22.04, only a few re­quire­ments need to be met. You need a server that is already running this version of the operating system. A non-root ad­min­is­tra­tor must also be set up on this server before the actual process begins. You should also set up a suitable firewall.

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

Update the package index

However, before you start in­stalling MariaDB on Ubuntu 22.04, you should update the entire system. The two apt commands are used to update the package index, all ap­pli­ca­tions and all de­pen­den­cies. This makes the in­stal­la­tion more secure and gets rid of any possible bugs. The cor­re­spond­ing commands are:

sudo apt update
sudo apt upgrade
bash

Install MariaDB on Ubuntu 22.04

Use the following in­struc­tions to install MariaDB on Ubuntu 22.04. As the SQL server is included in the Ubuntu repos­i­to­ry by default, no further steps are required for the actual in­stal­la­tion.

sudo apt install mariadb-server
bash

Configure the security script

The initial in­stal­la­tion is now finished. Currently, however, MariaDB is con­fig­ured with its default settings. This means, among other things, that there is no password set for access re­stric­tion. To address this, MariaDB provides a security script that allows you to make ad­di­tion­al con­fig­u­ra­tions. You can run this script with the following command:

sudo mariadb_secure_installation
bash

When the script is executed, it will first ask you for your root password for the database. As you have not yet stored a password, simply press [Enter] to select the no password option and continue.

Af­ter­wards, you will be prompted to set a root password for the database for au­then­ti­ca­tion. Because this is closely tied to various main­te­nance tasks in Ubuntu, it is advisable not to alter the login options at this stage. For security reasons, it is rec­om­mend­ed to press [N] and then [Enter]. In­struc­tions on how to create an ad­di­tion­al admin account with password pro­tec­tion will be provided below.

Begin by con­tin­u­ing with the security script. For the following prompts, respond with [Y] and press [Enter] to confirm. You will be asked whether you want to delete anonymous users, remove a test database, and restrict remote root access. At the end, you will be prompted to confirm if all changes should be applied im­me­di­ate­ly.

Create a password-protected admin user

The creation of an ad­di­tion­al admin user with password au­then­ti­ca­tion is optional, but solves a potential problem and thus increases security. By default, the root login for MariaDB takes place via the unix_socket plugin and therefore does not require a password. While this approach offers certain ad­van­tages, it can also cause issues when external programs need ad­min­is­tra­tive rights. The solution is to create an admin user with the same priv­i­leges as the root account, but au­then­ti­cat­ed with a password. To proceed, start by opening the command line for MariaDB:

sudo mariadb
bash

Now create a new user with admin rights, root priv­i­leges and password pro­tec­tion. To do this, replace the “username” and “password” place­hold­ers in the following code.

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

Now use FLUSH PRIVILEGES so that the changes are im­me­di­ate­ly applied.

FLUSH PRIVILEGES;
bash

Once you have done this, exit the MariaDB shell.

exit
bash

Test MariaDB

After in­stalling MariaDB on Ubuntu 22.04, it is rec­om­mend­ed to check if the setup was suc­cess­ful. You can verify the server status using the following command:

sudo systemctl status mariadb
bash

If the program does not run au­to­mat­i­cal­ly, you can also use this command to start it:

sudo systemctl start mariadb
bash
Go to Main Menu