How to Install MariaDB in Ubuntu 20.04/22.04

MariaDB has earned its stripes as a reputable database management system due to its feature-rich and performant nature. It being a MySQL fork implies that MariaDB offers similar features and performance metrics with the advantage of being free and completely open-source.

Therefore, for users that are invested in web-based or desktop-based application development projects, the input that mariaDB brings to the table cannot be ignored.

Prerequisites

Be a root/sudoer user on the Ubuntu system you wish to install MariaDB database management software.

Installing MariaDB in Ubuntu

An updated system is a performant system, make sure your Ubuntu system is up-to-date with the latest software.

$ sudo apt update && sudo apt upgrade -y 

Once your Ubuntu system is up-to-date, we can proceed and install MariaDB.

$ sudo apt install mariadb-server -y 
Install MariaDB in Ubuntu
Install MariaDB in Ubuntu

The installation process should take a minute or two to complete due to MariaDB’s light nature. Next, confirm the installed version of MariaDB on your Ubuntu system.

$ mariadb --version 
Check MariaDB Version
Check MariaDB Version

At this point, this article assumes you intend to use MariaDB as your primary database management software. We need to start and enable it so that it keeps on running even after the Ubuntu system shutdown or reboot.

$ sudo systemctl start mariadb 
$ sudo systemctl enable mariadb 
$ sudo systemctl status mariadb 
Check MariaDB Status in Ubuntu
Check MariaDB Status in Ubuntu

Securing MariaDB in Ubuntu

The following MariaDB pre-configuration security script ensures that set the root database user password and other warranted database configurations like removing anonymous users, disallowing remote login, removing test databases, before you can start using it.

$ sudo mysql_secure_installation
Secure MariaDB in Ubuntu
Secure MariaDB in Ubuntu

Next, you need to log in to your database to test MariaDB.

$ sudo mysql -u root -p 

Create a database user, database, and assign control over the created database to the user.

MariaDB [(none)]> CREATE USER [email protected] IDENTIFIED BY "Your_preferred_db_user_password";
MariaDB [(none)]> CREATE DATABASE linuxshelltips_db;
MariaDB [(none)]> GRANT ALL ON linuxshelltips_db.* TO [email protected]; 
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit
Create MySQL Database User in Ubuntu
Create MySQL Database User in Ubuntu

This article has walked us through installing, securing, and testing MariaDB database management software on the Ubuntu system.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.