How to install MariaDB on Ubuntu

Tobias Etzold • October 9, 2021


When you want to install MariaDB on Ubuntu you should first update your system. To do this, open your terminal and enter the following command.

$ sudo apt update && sudo apt upgrade

When your system is updated you can start by installing the MariaDB server.

$ sudo apt install mariadb-server 

When the installation routine is finished you should start the included security script.

$ sudo mysql_secure_installation

The root user should stay with its default empty password because this under Ubuntu the root mysql user is linked to the system root user which you normaly enter via sudo.

All other questions should be answered with yes.

Since the standard root user of MariaDB is linked to the system we now need to enter the MariaDB promt via super user.

$ sudo mysql

If MariaDB is not running, you can start it with the following command.

$ sudo service mysql start

When you are in the input promt of MariaDB you can add a new user and allow him to access all databases. This is your own root account.

CREATE USER 'username'@localhost IDENTIFIED BY 'secret'; 

GRANT ALL PRIVILEGES ON *.* TO 'username'@localhost;


After this, you should be able to access MariaDB with your custom user. Just enter the following command in your terminal and enter your specified password.

$ mysql -u username -p