How to Install MariaDB on Ubuntu 22.04

How to Install MariaDB on Ubuntu 22.04. In this guide, we discuss MariaDB and its features that are beneficial to individuals and organizations. After we navigate to steps how to install and interact with MariaDB.

What is MariaDB?

In the era of globalization and modernization, databases are extremely important for effectively managing, storing, and retrieving data. To fulfill the same purpose, a popular open source MariaDB, which is a relational database management system (RDBMS) has been developed. MariaDB offers additional features such as faster speed and improved security as a drop in alternative for MySQL.

Advantages of MariaDB

Open Source

Since MariaDB is open source software, which means anyone downloads, uses and modifies it for free. Due to this, it becomes a viable choice for companies and organizations of all sizes because they are exempted from paying steep licensing fees and vendor lock in concerns.


All in all, MariaDB offers Master slave replication features. This feature enables data to be replicated across many servers, guaranteeing that it is always accessible even in the case of a server failure. Moreover, it offers automated failover that enables the secondary server to take over in the event of a primary server failure without interfering with service.

High Performance

MariaDB is renowned for its outstanding scalability and performance. It is capable of handling millions of transactions per second and is built to manage massive, complicated databases. Supports a variety of storage engines, including InnoDB, MyRocks, and Aria. Each of which are customized for a particular task.

Advanced Security

Moreover, MariaDB offers advanced security features including two factor authentication, support for audit logging, and encryption for data in transit and at rest. Also, it adheres to industry accepted security standards by performing frequent security updates, vulnerability assessments, and bug fixes.

Enhanced compatibility

Since MariaDB is entirely compatible with MySQL, making it is simple to switch from MySQL to MariaDB without needing to make any changes to the application’s code. For this, it is a preferable option for businesses searching for a MySQL drop in replacement.

Community driven

The developers and contributors that work on MariaDB are passionate about building a better database system. This implies that the software is always evolving to cater to the needs of clients through updates, new features, and bug repairs.

Why MariaDB has a Promising Future?

The adoption of open source software by businesses and organizations is a rising trend worldwide. To help organizations make data driven decisions, the system is dedicated to enhancing its performance, securing features, and integrating with AI and ML technologies. So, MariaDB due to its simplicity, scalability, and dependability is well suited to meet the expanding needs of companies of all sizes. MariaDB continues to adapt and offer advanced solutions to assist organizations in managing their data efficiently and securely as the data landscape changes.

Also, it is natural to expect that demand for cloud based database management systems like MariaDB increases as more enterprises transfer their operations to the cloud.

How to Install MariaDB on Ubuntu 22.04

In this section, we show you How to Install MariaDB on 22.04 Ubuntu. In addition, there is a guide after that to learn how to create a database, user and table in MariaDB.


  • An Ubuntu 22.04 server is installed on your system.
  • A root user or a user with sudo privileges.

Update the System

Before doing anything, I would recommend to update and upgrade all the system packages to the latest version. Open your terminal and run the following command to update all the packages to the latest version.

					apt update -y
apt upgrade -y

Once all the packages are in a newer version, please proceed to add the MariaDB repository.

Add MariaDB Repository

By default, the MariaDB package is included in the Ubuntu default repository. However, it is a good idea to install the latest version of MariaDB from its official repository.

First, install all the necessary dependencies using the following command.

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

After installing all the dependencies, download and add the MariaDB GPG key using the following command.

					apt-key adv --fetch-keys ''

Next, add the MariaDB repository to the APT with the following command.

					add-apt-repository 'deb [arch=amd64,arm64,ppc64el] jammy main'

Once the repository is added to your system, you can update the repository cache using the following command.

					apt update -y

Install MariaDB Server

At this point, you are ready to install the latest version of the MariaDB server. Just run the following command to install both the MariaDB server and client package.

					apt install mariadb-server mariadb-client

After the successful installation, verify the MariaDB version using the following command.

					mariadb --version

You get the MariaDB version on the following screen.

To check the running status of the MariaDB service, run the following command.

					systemctl status mariadb

This shows you the MariaDB status on the following screen.

Also start and stop the MariaDB service using the following command.

					systemctl start mariadb
systemctl stop mariadb

Secure the MariaDB Installation

At this point, the MariaDB server is installed and running on your server. However, it is not secured yet. You will need to run the mysql_secure_installation script to secure the installation.


You will be asked to set a MariaDB root password as shown below:

Set your root password and press the Enter key. You will be asked to disable root login remotely.

Type Yes and press the Enter key. You are then asked to remove the anonymous user.

Type Yes and press the Enter key. You will be asked to remove the test database.

Type Yes and press the Enter key. Next reload the privileges table to secure the MariaDB installation.

Type Yes and press the Enter key to finish the process.

Create a Database and User in MariaDB

After installing and securing the MariaDB server. You also need to know how to interact with the MariaDB database. First, let’s connect to the MariaDB shell using the root user.

					mysql -u root -p

After providing your MariaDB root password log into the MariaDB shell.

Next, create a database called webdb using the following command.


To verify the created database, run the following command.


You should see all the databases on the following screen.

Next, create a new user called webadmin and grant all the privileges to the webdb database using the following command.

					GRANT ALL ON webdb.* TO 'webadmin'@'localhost' IDENTIFIED BY 'securepassword' WITH GRANT OPTION;

Now verify the created user using the following command.

					SELECT User, Host FROM mysql.user;

This shows you the MariaDB users on the following screen.

Now, flush the privileges table to apply the changes.


Next, exit from the MariaDB shell with the following command.


Create a Table in MariaDB

To create a table in MariaDB, let’s connect to the MariaDB using the newly created webadmin user.

					mysql -u webadmin -p

Next, change the database to webdb using the following command.

					USE webdb;

Now, create a table named books with the following command.

					CREATE TABLE books(title VARCHAR(50) NOT NULL,genre VARCHAR(30) NOT NULL,director VARCHAR(60) NOT NULL,publish_year INT NOT NULL,PRIMARY KEY(title));

Now verify the created table using the following command.

					SHOW tables;

This shows you the all tables on the following screen.

To see the detailed information of the books table, run the following command.

					DESCRIBE books;

You should see the following screen.

Next, insert one row in the table using the following command.

					INSERT INTO books VALUE ("computer", "hacking essential", "James warn", 2019);

To verify the inserted entry, run the following command.

					SELECT * FROM books;

You should see the following screen.

If you want to see only the title of the inserted entry, run the following command.

					SELECT title FROM books;

Remove MariaDB Database and Server

If you want to remove a webdb database, run the following command.

					DROP database webdb;

To remove the webadmin user, run the following command.

					DROP USER 'webadmin'@'localhost';

Now, remove the MariaDB server package with the following command.

					apt remove mariadb-server -y

After removing the MariaDB package, some dependencies still exist in your server. Remove all unwanted dependencies using the following command.

					apt autoremove
apt clean

Thank you for reading How to Install MariaDB on Ubuntu 22.04. We shall conclude the article. 

How to Install MariaDB on Ubuntu 22.04 Conclusion

Finally, MariaDB efficiently stored and retrieved data due to its secure and scalable database management system. What is more, MariaDB offers advanced features such as high performance, high availability, and security, etc.

The system has the tools you need to complete the task, whether you’re in charge of a huge enterprise system or a modest personal database. Existing applications can be easily switched to MariaDB due to its compatibility with MySQL. So why not give it a shot and see what it can do for yourself!

Do explore more of MariaDB content in our blog by clicking here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x