How to Install MariaDB on Ubuntu 26.04

Updated on 24 April, 2026
Install and secure the MariaDB relational database server on an Ubuntu 26.04 with performance configuration and database management basics.
How to Install MariaDB on Ubuntu 26.04 header image

MariaDB is an open-source relational database management system built as a drop-in replacement for MySQL. It offers improved performance, additional storage engines, and enhanced security features while maintaining full compatibility with MySQL syntax and tools. MariaDB is commonly used in web application stacks, data analytics platforms, and enterprise environments.

This article explains how to install MariaDB on an Ubuntu 26.04 server. It covers the database server setup, service management, security hardening, and basic database operations including user creation and privilege management.

Prerequisites

Before you begin, you need to:

Install MariaDB on Ubuntu 26.04

The default Ubuntu 26.04 APT repositories include the MariaDB server package. The following steps install the database server and verify the service status.

  1. Update the APT package index.

    console
    $ sudo apt update
    
  2. Install the MariaDB server package.

    console
    $ sudo apt install mariadb-server -y
    
  3. Confirm the installed MariaDB version.

    console
    $ mariadb --version
    

    Your output should be similar to the one below:

    mariadb from 11.8.6-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using  EditLine wrapper
  4. Enable MariaDB to start automatically at boot time.

    console
    $ sudo systemctl enable mariadb
    
  5. Start the MariaDB service.

    console
    $ sudo systemctl start mariadb
    
  6. Verify that MariaDB is active and running.

    console
    $ sudo systemctl status mariadb
    

    The output should display active (running), confirming that the MariaDB server is operational.

Secure the MariaDB Server

A default MariaDB installation allows the root user to access the database console without a password. The mysql_secure_installation script assigns a root password, removes anonymous accounts, disables remote root login, and drops the test database.

  1. Run the MariaDB security script.

    console
    $ sudo mariadb-secure-installation
    

    Respond to each prompt as described below:

    • Enter current password for root: Press Enter to proceed with no current password.
    • Switch to unix_socket authentication: Enter N and press Enter to use password-based authentication.
    • Change the root password?: Enter Y and press Enter to set a new root password.
    • New password: Enter a strong password for the root account.
    • Re-enter new password: Re-enter the password to confirm.
    • Remove anonymous users?: Enter Y to delete anonymous database accounts.
    • Disallow root login remotely?: Enter Y to restrict root access to the local server.
    • Remove test database and access to it?: Enter Y to drop the default test database.
    • Reload privilege tables now?: Enter Y to refresh the privilege tables and apply all changes.
  2. Restart MariaDB to apply the new security settings.

    console
    $ sudo systemctl restart mariadb
    

Access MariaDB

The mariadb command-line client provides direct access to the database console. It is also compatible with the mysql command and graphical tools such as phpMyAdmin. The following steps log in as the root user, create a database, and configure a dedicated user with appropriate privileges.

  1. Log in to the MariaDB console as the root user.

    console
    $ mariadb -u root -p
    

    Enter the root password you configured in the previous section.

  2. Create a new database named example_db.

    sql
    MariaDB [(none)]> CREATE DATABASE example_db;
    
  3. Verify that the database exists.

    sql
    MariaDB [(none)]> SHOW DATABASES;
    

    Your output should be similar to the one below:

    +--------------------+
    | Database           |
    +--------------------+
    | example_db         |
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    5 rows in set (0.001 sec)
  4. Create a database user named example_user with a strong password. Replace strong_password with your desired password.

    sql
    MariaDB [(none)]> CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'strong_password';
    
  5. Grant the user full privileges on the example_db database.

    sql
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
    
  6. Reload the privilege tables to activate the new user permissions.

    sql
    MariaDB [(none)]> FLUSH PRIVILEGES;
    
  7. Exit the MariaDB console.

    sql
    MariaDB [(none)]> EXIT;
    

Create a Sample Database Table

The example_user account has the privileges required to create and manage tables within the example_db database. The following steps log in as that user, create a table, insert sample records, and query the data.

  1. Log in to MariaDB as the example_user.

    console
    $ mariadb -u example_user -p
    

    Enter the example_user password when prompted.

  2. Switch to the example_db database.

    sql
    MariaDB [(none)]> USE example_db;
    
  3. Create a table named employees with columns for an auto-incrementing ID, a name, a department, and a hire date.

    sql
    MariaDB [example_db]> CREATE TABLE employees (
             id INT AUTO_INCREMENT PRIMARY KEY,
             name VARCHAR(100) NOT NULL,
             department VARCHAR(50),
             hire_date DATE
             );
    
  4. Insert sample records into the employees table.

    sql
    MariaDB [example_db]> INSERT INTO employees (name, department, hire_date) VALUES
           ('Alice Johnson', 'Engineering', '2025-03-15'),
           ('Bob Carter', 'Marketing', '2024-11-01'),
           ('Clara Davis', 'Operations', '2026-01-20');
    
  5. Query the table to verify the inserted data.

    sql
    MariaDB [example_db]> SELECT * FROM employees;
    

    Your output should be similar to the one below:

    +----+---------------+-------------+------------+
    | id | name          | department  | hire_date  |
    +----+---------------+-------------+------------+
    |  1 | Alice Johnson | Engineering | 2025-03-15 |
    |  2 | Bob Carter    | Marketing   | 2024-11-01 |
    |  3 | Clara Davis   | Operations  | 2026-01-20 |
    +----+---------------+-------------+------------+
    3 rows in set (0.000 sec)
  6. Exit the MariaDB console.

    sql
    MariaDB [example_db]> EXIT;
    

Conclusion

You have installed and secured MariaDB on an Ubuntu 26.04 server, configured password-based authentication, and created a dedicated database user. MariaDB integrates with web application stacks such as LAMP and LEMP, and supports replication for high-availability deployments. For more information, refer to the official MariaDB documentation.

Comments