---
title: How to Install MariaDB on Ubuntu 22.04
url: https://docs.vultr.com/how-to-install-mariadb-on-ubuntu-2204
description: Learn how to install MariaDB on Ubuntu 22.04 with our step-by-step guide. Includes configuration tips, security best practices, and troubleshooting advice.
publish_date: 2025-04-29T11:46:26.457000Z
last_updated: 2025-04-29T12:09:12.218000Z
author: Aashish Chaurasiya
header_image: https://docs.vultr.com/public/doc-assets/2169/91e539e2-6e0f-4066-9b73-12b0c23e65ea.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

MariaDB is an open-source relational database management system that serves as a drop-in replacement for MySQL, offering improved reliability, performance, and flexibility. It uses the same SQL syntax as MySQL for creating and managing databases on a server.

This article explains how to install MariaDB on Ubuntu 22.04 and configure it for production use, enabling you to create and manage databases on your server.

## Prerequisites

Before you begin:

* Have an [Ubuntu 22.04 server](https://www.vultr.com/servers/ubuntu/).
* Access the server using SSH as a non-root user with sudo privileges.
* [Update the server](https://docs.vultr.com/how-to-update-a-vultr-cloud-server#how-to-update-debian-&-ubuntu).

## Install MariaDB on Ubuntu 22.04

MariaDB is available in the default APT repositories on Ubuntu 22.04. Follow the steps below to install the MariaDB Server package and verify the system service status.

1. Update the server package index.

    ```console
    $ sudo apt update
    ```

1. Install MariaDB.

    ```console
    $ sudo apt install mariadb-server -y
    ```

1. View the installed MariaDB version on your server.

    ```console
    $ mariadb --version
    ```

    Output:

    ```
    mariadb  Ver 15.1 Distrib 10.6.21-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
    ```

1. Enable the system service to start at boot time.

    ```console
    $ sudo systemctl enable mariadb
    ```

1. Start the MariaDB service on your server.

    ```console
    $ sudo systemctl start mariadb
    ```

1. View the MariaDB service status to verify that it's running on your server.

    ```console
    $ sudo systemctl status mariadb
    ```

    Output:

    ```
    ● mariadb.service - MariaDB 10.6.21 database server
        Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
        Active: active (running) since Sat 2025-04-05 16:08:38 UTC; 12min ago
        Docs: man:mariadbd(8)
                https://mariadb.com/kb/en/library/systemd/
    Main PID: 2541 (mariadbd)
        Status: "Taking your SQL requests now..."
        Tasks: 7 (limit: 61946)
        Memory: 61.5M
            CPU: 406ms
        CGroup: /system.slice/mariadb.service
                └─2541 /usr/sbin/mariadbd
    ```

## Secure the MariaDB Server

MariaDB runs with the default `root` user account without a password, allowing only privileged users to access the server. Follow the steps below to secure the MariaDB server by setting a root password, removing anonymous users, and disabling remote access for the root user.

1. Run the following command to start the MariaDB security script.

    ```console
    $ sudo mysql_secure_installation
    ```

    * Press :key_enter: to select `none` as the current root password.

        ```
        Enter current password for root (enter for none): 
        ```

    * Enter :key_n: and press :key_enter: to use MariaDB without `unix_socket` authentication.

        ```
        Switch to unix_socket authentication [Y/n]
        ```

    * Enter :key_y: and press :key_enter: to change the default root user password.

        ```
        Change the root password? [Y/n] 
        ```

    * Enter a new strong password for the root user.

        ```
        New password: 
        ```

    * Re-enter the new root user password and press :key_enter: to save changes.

        ```
        Re-enter new password: 
        ```

    * Enter :key_y: and press :key_enter: to delete anonymous users on the MariaDB server.

        ```
        Remove anonymous users? [Y/n]
        ```

    * Enter :key_y: and press :key_enter: to disable remote access to the database server root user.

        ```
        Disallow root login remotely? [Y/n]
        ```

    * Enter :key_y: and press :key_enter: to delete the test database.

        ```
        Remove test database and access to it? [Y/n]
        ```

    * Enter :key_y: to refresh your MariaDB privilege tables and apply your new configuration changes.

        ```
        Reload privilege tables now? [Y/n]
        ```

1. Restart MariaDB on your server.

    ```console
    $ sudo systemctl restart mariadb
    ```

## Access MariaDB

MariaDB is compatible with graphical management tools like PhpMyAdmin, which integrate directly with the database server. You can access the MariaDB console using the `mariadb` or `mysql` command. Follow the steps below to access the MariaDB console and create sample databases on your server.

1. Log in to the MariaDB database server.

    ```console
    $ mariadb -u root -p
    ```

    Enter the database root user password you set earlier when prompted.

1. Create a new sample database. For example, `exampledb`.

    ```sql
    MariaDB [(none)]> CREATE DATABASE exampledb;
    ```

1. View all databases on the server and verify that the new database is available.

    ```sql
    MariaDB [(none)]> SHOW DATABASES;
    ```

    Output:

    ```
    +--------------------+
    | Database           |
    +--------------------+
    | exampledb          |
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    5 rows in set (0.001 sec)
    ```

1. Create a new database user with a strong password. For example, `exampledb_user`.

    ```sql
    MariaDB [(none)]> CREATE USER 'exampledb_user'@'localhost' IDENTIFIED BY 'secure_password';
    ```

1. Grant the user full privileges to the `exampledb` database.

    ```sql
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON exampledb.* TO 'exampledb_user'@'localhost';
    ```

1. Refresh the MariaDB privilege tables to apply the new database changes.

    ```sql
    MariaDB [(none)]> FLUSH PRIVILEGES;
    ```

1. Exit the MariaDB database console.

    ```sql
    MariaDB [(none)]> EXIT;
    ```

## Conclusion

In this article, you installed and configured MariaDB on an Ubuntu 22.04 server. You can now integrate the database server with your applications to use MariaDB as the backend. For more information and configuration options, please visit the official [MariaDB documentation](https://mariadb.com/kb/en/documentation/).
