MariaDB is an open-source relational database management system. Originally designed as a replacement for backward-compatible binary MySQL backward.
MariaDB was developed and managed by the original MySQL developer and by the open-source community.
This guide explains how to install and secure MariaDB on Ubuntu 20.04.
We assume that you have administrative access to the Ubuntu server, either as root or as a user with sudo permission.
Install MariaDB on Ubuntu
At the time of writing this article, the latest version of MariaDB available in the Ubuntu repository is version 10.3. To install it run the following command:
sudo apt update
sudo apt install mariadb-server
After the installation is complete, the MariaDB service will start automatically. To verify that the database server is running, type:
sudo systemctl status mariadb
The output will indicate that the service is activated and running:
The MariaDB server package comes with a script called mysql_secure_installation which allows you to easily increase the security of the database server.
Run the script without arguments:
The script will ask you to enter the root password:
Enter current password for root (enter for none):
Since you haven’t set a root password, just press “Enter” here.
At the next prompt, you will be asked to set a password for the MySQL root user:
Set root password? [Y/n] n
Type n. On Ubuntu, the MariaDB root user is authenticated by the auth_socket plugin by default. This plugin works by checking whether the local system user running the client program matches the specified MariaDB username.
Next, you will be asked to delete anonymous users, restrict root user access to the local machine, delete the test database, and load the privilege table again. You must answer Y for all questions:
Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
Log in as root
To interact with the MariaDB server from the command line, use the mysql client utility or the alias mariadb. This tool is installed as a dependency from the MariaDB server package.
The auth_socket plugin authenticates users who are connected from localhost via a Unix socket file. This means you cannot authenticate as root by providing a password.
To log in to the MariaDB server as the root user type:
You will be presented with the MariaDB shell, as shown below:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 61 Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> Bye
If you want to log in to your MariaDB server as root using an external program like phpMyAdmin, you have two options.
The first is to change the authentication method from auth_socket to mysql_native_password. You can do this by running the following command:
Maria DB-> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
Second, the recommended option is to create a new dedicated administrative user with access to all databases:
GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';
You can give whatever administrative username you want, but make sure you use a strong password.
We have shown you how to install MariaDB on Ubuntu 20.04. Now that your database server is up and running, your next step is to learn how to manage MariaDB user accounts and user databases.
If you have questions or feedback, don’t hesitate to leave a comment.