How to install MariaDB on Ubuntu 20.04
To install MariaDB on Ubuntu 20.04, simply follow these steps:
- Update the system
- Initiate the installation
- Customize the security script
- Create password-protected admin user (optional)
- Check the installation
In the following sections, we will guide you step by step through the installation.
MariaDB as part of the LAMP stack
MariaDB has established 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 architecture. MariaDB can be seamlessly integrated into the LAMP stack (Linux, Apache, MySQL, and PHP, Python, or Perl) for Ubuntu as a drop-in replacement without any modifications or issues. In this guide, we provide step-by-step instructions on how to install and configure MariaDB on Ubuntu 20.04.
If you are using a newer version of the Linux distribution, you will also find detailed instructions for installing MariaDB on Ubuntu 22.04 in our Digital Guide.
The requirements
Only a few requirements 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 administrative non-root user must be set up. The best possible way to secure the installation is with a suitable firewall.
- Cost-effective vCPUs and powerful dedicated cores
- Flexibility 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 corresponding apt
commands to update the package index and ensure that all files and dependencies are up to date. This is for security reasons so that you can work with a bug-free server. The corresponding commands are as follows:
sudo apt update
sudo apt upgrade
bashInstall MariaDB on Ubuntu 20.04
If your system including all packages has been successfully updated, you can start installing MariaDB on Ubuntu 20.04. Use the following command to unpack the packages of the database management system that are already included in the Ubuntu repository:
sudo apt install mariadb-server
bashOnly the installation is performed in this step. Important security measures and configurations 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 application’s security. You can execute the script with the following command:
sudo mariadb_secure_installation
bashWhen 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 maintenance. It is therefore advisable not to change the authentication options for the time being. Type in [N] and confirm with [Enter].
You can confirm the script’s additional settings by pressing [Y] and [Enter]. Among other prompts, you will be asked if you wish to remove anonymous users and the test database. Furthermore, remote root logins will be disabled. Finally, the script will ask if you want to apply all changes immediately.
Optionally 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 additional administrator 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 complications as soon as external programs require administrative rights. Therefore, as a precaution, create an additional account that has admin rights and password protection. To do this, first open the MariaDB command prompt:
sudo mariadb
bashNext, create the new admin and set a password. Adjust the “username” and “password” placeholders to suit your needs:
GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
bashThen use FLUSH PRIVILEGES
to apply the changes immediately:
FLUSH PRIVILEGES;
bashThen exit the MariaDB shell:
exit
bashCheck 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
bashMariaDB is executed automatically by default. If this is not the case, you can access the database using the following command:
sudo systemctl start mariadb
bash