How to install MariaDB on Ubuntu 22.04
Simply follow these steps to install MariaDB on Ubuntu 22.04:
- Update the system
- Install the database
- Configure the security script
- Create additional admin with password protection (optional)
- Test MariaDB
This article shows you the individual steps that need to be carried out.
MariaDB as a drop-in replacement for MySQL
The relational database management system MariaDB was first published in 2009 as a fork of MySQL and is now considered a strong alternative to this SQL server. Even in comparison with MySQL, the fork impresses with its high flexibility and excellent security architecture. As a drop-in replacement for MySQL, MariaDB can be integrated 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 repository. Below we explain how to install MariaDB on Ubuntu 22.04.
If you want to use an older version of the Linux distribution, you will also find detailed instructions for how to install MariaDB on Ubuntu 20.04 in our Digital Guide.
The necessary requirements
If you want to install MariaDB on Ubuntu 22.04, only a few requirements need to be met. You need a server that is already running this version of the operating system. A non-root administrator must also be set up on this server before the actual process begins. You should also set up a suitable firewall.
- Cost-effective vCPUs and powerful dedicated cores
- Flexibility with no minimum contract
- 24/7 expert support included
Update the package index
However, before you start installing MariaDB on Ubuntu 22.04, you should update the entire system. The two apt commands are used to update the package index, all applications and all dependencies. This makes the installation more secure and gets rid of any possible bugs. The corresponding commands are:
sudo apt update
sudo apt upgrade
bashInstall MariaDB on Ubuntu 22.04
Use the following instructions to install MariaDB on Ubuntu 22.04. As the SQL server is included in the Ubuntu repository by default, no further steps are required for the actual installation.
sudo apt install mariadb-server
bashConfigure the security script
The initial installation is now finished. Currently, however, MariaDB is configured with its default settings. This means, among other things, that there is no password set for access restriction. To address this, MariaDB provides a security script that allows you to make additional configurations. You can run this script with the following command:
sudo mariadb_secure_installation
bashWhen 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.
Afterwards, you will be prompted to set a root password for the database for authentication. Because this is closely tied to various maintenance tasks in Ubuntu, it is advisable not to alter the login options at this stage. For security reasons, it is recommended to press [N] and then [Enter]. Instructions on how to create an additional admin account with password protection will be provided below.
Begin by continuing 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 immediately.
Create a password-protected admin user
The creation of an additional admin user with password authentication 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 advantages, it can also cause issues when external programs need administrative rights. The solution is to create an admin user with the same privileges as the root account, but authenticated with a password. To proceed, start by opening the command line for MariaDB:
sudo mariadb
bashNow create a new user with admin rights, root privileges and password protection. To do this, replace the “username” and “password” placeholders in the following code.
GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
bashNow use FLUSH PRIVILEGES
so that the changes are immediately applied.
FLUSH PRIVILEGES;
bashOnce you have done this, exit the MariaDB shell.
exit
bashTest MariaDB
After installing MariaDB on Ubuntu 22.04, it is recommended to check if the setup was successful. You can verify the server status using the following command:
sudo systemctl status mariadb
bashIf the program does not run automatically, you can also use this command to start it:
sudo systemctl start mariadb
bash