Jun 9, 2023 6 min read

Installing MariaDB on Ubuntu 22.04 – A Quick Guide to Get You Started

Install MariaDB on Ubuntu 22.04 with our step-by-step tutorial. It's an open-source RDBMS known for its performance, scalability and reliability.

Installing MariaDB on Ubuntu 22.04
Table of Contents

Choose a different version or distribution


Before we begin talking about how to install MariaDB on Ubuntu 22.04, let's first understand – What is MariaDB?

MariaDB is a popular open-source relational database management system (RDBMS) that offers high-performance, scalability, and reliability. It was developed as a fork of MySQL and is compatible with its predecessor.

MariaDB provides a seamless transition for MySQL users while offering additional features and improvements. With its robust architecture and extensive community support, MariaDB has become a preferred choice for businesses seeking a reliable and efficient database solution.

In this tutorial, you will install MariaDB on Ubuntu 22.04. We will also address a few FAQs on How to Install MariaDB on Ubuntu 22.04.

Advantages of MariaDB

  1. Performance: MariaDB offers enhanced performance with optimized query execution and faster response times.
  2. Scalability: It allows seamless scaling to handle growing data and user demands effectively.
  3. Reliability: MariaDB ensures data integrity and offers features like replication and backup for high availability.
  4. Compatibility: It is compatible with MySQL, making it easy for existing MySQL users to migrate to MariaDB.
  5. Community Support: MariaDB has a large and active community that provides extensive support, updates, and resources.

Prerequisites to Install MariaDB on Ubuntu 22.04

  • One Ubuntu 22.04 server
  • A firewall and a non-root user with sudo privileges

Step 1 – Installing MariaDB

MariaDB version 10.6 is present by default in the APT package repositories for Ubuntu 22.04.

1) Before starting the installation process, use the following command to update the package index on the server:

sudo apt update

2) Use the following command to start the installation process:

sudo apt install mariadb-server

3) The commands mentioned above will configure MariaDB. You will not be asked to select a password or change any other settings. This is because the installation of MariaDB is insecure by default; you must now use the script provided by the MariaDB-server package to restrict access to the server and remove unused accounts to make MariaDB more secure.

Step 2 – Configuring MariaDB

1) The first step in installing MariaDB is to run the provided security script. This script changes certain default parameters to improve MariaDB's security. The commands listed below will prevent remote root logins and remove inactive database users.

First, run the security script provided below:

sudo mysql_secure_installation

2) This will direct you to several prompts where you can modify MariaDB's security settings. You will be prompted to provide the most recent database root password. Just press ENTER if you have not configured a database root password.

3) The subsequent popup will ask if you would like to set up a database root password. Press ENTER after typing N to indicate that you do not want to set a root password. The root account for MariaDB on the Ubuntu server should not be modified. In the same way, removing access to the administrative account would allow a package update to break the database system.

We will cover how to set up a second administrative account for password access in the following step, just in case socket authentication is not the best option.

4) To accept the default setting for all ensuing prompts, you must then press Y and then hit ENTER. This would make sure that any anonymous users could not access your database and load the new rules so that MariaDB would immediately take into account the modifications you made.

Step 3 (Optional) – Adjusting User Authentication and Privileges

1) The root MariaDB user is configured on the Ubuntu system that hosts MariaDB 10.6 to activate by default using the unix_socket plugin rather than a password. This guarantees a higher level of security and usefulness, but it may make things more difficult if you need to give administrative rights to external software.

We advise against changing the root account's authentication information because the server uses it for rotating logs and starting and stopping the operation of the server. Initially, doing so in the configuration file /etc/mysql/debian.cnf may work, but package upgrades may replace such changes.

The package maintainers advise creating a different admin account with password-based access as an alternative to changing the root account.

In order to do this, we must first create a new account called admin with the same permissions as the root account, and this account must be set up for password authentication. To begin, use the following command from your terminal to launch the MariaDB prompt:

sudo mysql

2) Create a new account with root access now, and modify the username and password to something more appropriate for you.

GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

3) Execute a flush operation on the privileges to ensure that they are saved and accessible during the current session.


4) Next, use the procedure below to leave the MariaDB shell:


We will test MariaDB in the following step.

Step 4 – Testing MariaDB

1) When MariaDB is installed using the default repositories, it typically runs automatically. Use the following command to check its status and confirm its installation and operation:

sudo systemctl status mariadb

The output will look something like this:


mariadb.service - MariaDB 10.1.44 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-10-16 16:51:16 UTC; 8min ago
     Docs: man:mysqld(8)
 Main PID: 22559 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 1152)
   CGroup: /system.slice/mariadb.service
           └─22559 /usr/sbin/mysqld

Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: mysql
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: performance_schema
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: Phase 6/7: Checking and upgrading tables
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: Processing databases
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: information_schema
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: performance_schema
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22596]: OK
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22658]: Checking for insecure root accounts.
Oct 16 16:51:17 ubuntu-mariadb /etc/mysql/debian-start[22663]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

2) Use the sudo systemctl start mariadb command to make MariaDB operational if it is not already.

To make sure, try establishing a connection to the database using the mysqladmin tool, which is a client that enables you to issue administrative commands. Using the Unix socket, the following command, for instance, will connect the user to MariaDB as root and return the version:

sudo mysqladmin version

When you enter the command, something like this should appear:


mysqladmin  Ver 9.1 Distrib 10.1.44-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version      10.1.44-MariaDB-0ubuntu0.18.04.1
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /var/run/mysqld/mysqld.sock
Uptime:         10 min 9 sec

Threads: 1  Questions: 445  Slow queries: 0  Opens: 167  Flush tables: 1  Open tables: 30  Queries per second avg: 0.730

3) If a separate administrative user with password authentication has been set up, the exact operation can be carried out by using:

mysqladmin -u admin -p version

Essentially, this signifies that MariaDB is up and running and that your user was able to authenticate successfully.

FAQs to Install MariaDB on Ubuntu 22.04

How can I secure the MariaDB installation on Ubuntu 22.04?

After installation, run the command sudo mysql_secure_installation to set a root password, remove anonymous users, and tighten security.

How do I start and stop the MariaDB service on Ubuntu 22.04?

To start MariaDB, use sudo systemctl start mariadb.service. To stop it, run sudo systemctl stop mariadb.service.

How can I enable MariaDB to start automatically on system boot?

You can enable this feature by running the command sudo systemctl enable mariadb.service.

How do I access the MariaDB command-line interface on Ubuntu 22.04?

Use the command sudo mysql to access the MariaDB command-line interface.

How can I create a new user in MariaDB on Ubuntu 22.04?

Log in to the MariaDB CLI as the root user, then run the command CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';.

How do I create a new database in MariaDB on Ubuntu 22.04?

In the MariaDB CLI, use the command CREATE DATABASE dbname; to create a new database.

How can I uninstall MariaDB from Ubuntu 22.04?

Run the command sudo apt remove mariadb-server to uninstall MariaDB from Ubuntu 22.04.


In this tutorial, you installed MariaDB on Ubuntu 22.04. Visit the official MariaDB documentation to understand more about MariaDB installation.

If you have any questions, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.