How to Install MariaDB on Ubuntu 22.04

There are numerous relational databases available such as Oracle, MySQL, PostgreSQL, and MariaDB is one of them. MariaDB uses SQL queries to manipulate databases. It is an effective tool for searching, adding, and updating data. Most cloud services utilize MariaDB, which is standard in some Linux variants. This database is also used to achieve enterprise-level features, e-commerce, logging applications, and data warehousing.

MariaDB installation on Ubuntu 22.04

On Ubuntu 22.04, to install MariaDB, go through the provided steps.

Step 1: Update system packages

In the first step, open Ubuntu’s terminal by pressing “CTRL+ALT+T”. Then update and upgrade the system packages:

$ sudo apt update && sudo apt upgrade -y

Step 2: Install additional dependencies

Install and set additional dependencies that are required for MariaDB:

$ sudo apt-get install wget software-properties-common dirmngr ca-certificates apt-transport-https -y

Let’s move ahead to get the GPG key.

Step 3: Import MariaDB GPG key

MariaDB is not available directly on the Ubuntu system. Therefore, it is necessary to import the GPG key to install MariaDB on Ubuntu 22.04:

$ sudo wget -O- https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor | sudo tee /usr/share/keyrings/mariadb.gpg

Go on to the following step to add the MariaDB repository.

Step 4: Add MariaDB repository

Now, add MariaDB repository in the Ubuntu 22.04 system using the provided command:

$ echo deb [arch=amd64,arm64,ppc64el,s390x signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.8/ubuntu/ jammy main | sudo tee /etc/apt/sources.list.d/mariadb.list

Move forward to update the Ubuntu system.

Step 5: Update system packages

After adding MariaDB repository, again update the system packages:

$ sudo apt update

Step 6: Install MariaDB

Finally, install MariaDB by utilizing the following command:

$ sudo apt install mariadb-server mariadb-client -y

Step 7: Check status of MariaDB

In order to check the status of MariaDB, execute the below-provided command:

$ systemctl status mariadb

Step 8: Set MariaDB

Execute the MySQL security script to secure MariaDB and answer the asked information according to your preferences:

$ sudo mysql_secure_installation

As you can see, we have successfully installed and secured MariaDB.

How to upgrade MariaDB on Ubuntu 22.04?

To upgrade the MariaDB and enjoy the latest version, execute the mentioned command:

$ sudo mariadb-upgrade

The given output indicates that our MariaDB is “10.8.3-MariaDB” up to date:

Now, let’s head towards the procedure to use MariaDB on Ubuntu 22.04.

How to use MariaDB on Ubuntu 22.04?

On Ubuntu 22.04, to use MariaDB on the command line, follow the listed steps.

Step 1: Login to MariaDB

In the first step, provide the MariaDB default username and password to log in to the MariaDB server. For doing so, execute the provided command:

$ sudo mysql -u root -p

After logging into MariaDB, move ahead to create a new database.

Step 2: Create new Database

Next, create a new database as we have created “itslinuxfoss” database:

> CREATE DATABASE itslinuxfoss;

Step 3: Set username and password detail

Set the new username and password for a newly created database:

G> RANT ALL PRIVILEGES ON itslinuxfoss.* TO 'itslinuxfoss'@'localhost' IDENTIFIED BY "Root";

Step 4: Save settings and exit MariaDB

To save the settings and leave MariaDB, run the following commands:

> FLUSH PRIVILEGES;
> QUIT;

Let’s check the procedure to remove MariaDB from Ubuntu 22.04.

How to remove MariaDB server from Ubuntu 22.04?

On Ubuntu 22.04, to remove MariaDB, utilize the below-provided command:

$ sudo apt autoremove mariadb-server mariadb-client --purge -y

In the opened “Package configuration” wizard, select “Yes” option to remove all MariaDB databases:

As you can see, we have successfully removed MariaDB from Ubuntu 22.04:

Let’s remove the source list of the MariaDB repository using the below-provided command:

$ sudo rm /etc/apt/sources.list.d/mariadb.list

We have successfully elaborated the methods to install, use, and remove MariaDB on Ubuntu 22.04.

Conclusion

MariaDB relational database and cannot be directly installable on Ubuntu 22.04. To install MariaDB, first, import the GPG key that allows local users to access MariaDB. After doing so, add the MariaDB repository to your system. Then, execute the “$ sudo apt install mariadb-server mariadb-client -y” command for the MariaDB server and MariaDB client installation. This blog has effectively demonstrated the methods to install, use, and remove MariaDB on Ubuntu 22.04.