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­vidu­al 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­sidered a strong al­tern­at­ive to this SQL server. Even in com­par­is­on with MySQL, the fork impresses with its high flex­ib­il­ity and excellent security ar­chi­tec­ture. As a drop-in re­place­ment for MySQL, MariaDB can be in­teg­rated 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 re­pos­it­ory. 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­bu­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­trat­or 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­ib­il­ity 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­plic­a­tions and all de­pend­en­cies. This makes the in­stall­a­tion more secure and gets rid of any possible bugs. The cor­res­pond­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 re­pos­it­ory by default, no further steps are required for the actual in­stall­a­tion.

sudo apt install mariadb-server
bash

Configure the security script

The initial in­stall­a­tion is now finished. Currently, however, MariaDB is con­figured 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­ur­a­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­tic­a­tion. Because this is closely tied to various main­ten­ance tasks in Ubuntu, it is advisable not to alter the login options at this stage. For security reasons, it is re­com­men­ded 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­tinu­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­ately.

Create a password-protected admin user

The creation of an ad­di­tion­al admin user with password au­then­tic­a­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­vant­ages, it can also cause issues when external programs need ad­min­is­trat­ive rights. The solution is to create an admin user with the same priv­ileges as the root account, but au­then­tic­ated 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­ileges 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­ately 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 re­com­men­ded 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 auto­mat­ic­ally, you can also use this command to start it:

sudo systemctl start mariadb
bash
Go to Main Menu