How to install MariaDB on Ubuntu 26.04

How to install MariaDB on Ubuntu 26.04

In this guide, we will walk you through how to install MariaDB on Ubuntu 26.04. MariaDB is a free, open-source relational database management system that serves as a replacement for MySQL, offering better performance, improved flexibility, and enhanced reliability. It comes with advanced features such as Galera Cluster support and a wide range of data types. MariaDB was developed by the original MySQL creators due to concerns following Oracle’s acquisition of MySQL. In the sections below, we will cover how to install, secure, and use the MariaDB database service.

The MariaDB installation process is simple and usually takes no more than 10 minutes. Let’s begin!

Prerequisites

Step 1. Update the System

We assume you are working with a fresh Ubuntu 26.04 OS installation. Before starting the MariaDB installation, it is recommended to update all system packages. You can do this by running the following command:

apt update -y && apt upgrade -y

Step 2. Install MariaDB database

MariaDB is included in the default Ubuntu 26.04 repositories. To install the MariaDB database server, run the command below:

apt install mariadb-server -y

Once the installation is complete, start the MariaDB service and enable it to run automatically at system startup with the following commands:

systemctl start mariadb && systemctl enable mariadb

To verify that the MariaDB service is running correctly, execute the command below:

systemctl status mariadb

You should receive output similar to the following:

root@host:~# systemctl status mariadb
● mariadb.service - MariaDB 11.8.6 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running) since Wed 2026-04-08 10:15:28 CDT; 16s ago
Invocation: dd2259595b9c413bb2ac5777adbd54f3
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 2271 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 26579)
Memory: 93.4M (peak: 98.2M)
CPU: 4.787s
CGroup: /system.slice/mariadb.service
└─2271 /usr/sbin/mariadbd

Step 3. Securing the MariaDB Installation

After installation, it is very important to secure your MariaDB setup to prevent unauthorized access and protect your data. To begin the security configuration, run the following command:

mariadb-secure-installation

After running the command, follow the prompts below to complete the security setup:

Enter current password for root (enter for none):

Switch to unix_socket authentication [Y/n] Y

Change the root password? [Y/n] Y
New password: StrongROOTPasswordHere
Re-enter new password: StrongROOTPasswordHere

Remove anonymous users? [Y/n] Y

Disallow root login remotely? [Y/n] Y

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

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Most Useful MariaDB commands

Below is a list of some of the most commonly used and important MariaDB commands and SQL statements:

CREATE DATABASE db_name;                                Create a brand new database.

DROP DATABASE db_name; Remove a database permanently.

USE db_name; Switch to a specific database.

CREATE TABLE table_name ( … ); Define and create a new table.

SHOW DATABASES; Display all available databases.

SHOW TABLES; Show all tables in the selected database.

SHOW TABLE STATUS LIKE 'table_name'; View detailed information about a table (engine, size, etc).

SHOW COLUMNS FROM table_name; List all columns in a table.

SHOW INDEX FROM table_name; Show indexing details for a table.

DESCRIBE table_name; or SHOW COLUMNS FROM table_name; Display the structure of a table.

DESCRIBE table_name; Alternative command to view table structure.

ALTER TABLE table_name …; Change the structure of a table.

DROP TABLE table_name; Delete a table along with its contents.

SELECT … FROM …; Fetch data from one or more tables.

INSERT INTO table_name (…) VALUES (…); Insert new records into a table.

UPDATE table_name SET … WHERE …; Modify existing records in a table.

DELETE FROM table_name WHERE …; Remove specific records from a table.

CREATE USER 'user'@'host' IDENTIFIED BY 'password'; Add a new database user.

GRANT privileges ON db.table TO 'user'@'host'; Provide access rights to a user.

REVOKE privileges ON db.table FROM 'user'@'host'; Remove assigned permissions from a user.

FLUSH PRIVILEGES; Apply privilege changes immediately.

These are among the most essential MariaDB commands. However, the most important step is logging into the MariaDB console, as you must be logged in to execute any of the commands listed above. Use the following command to log in:

mariadb -u user_name -p

Here is a brief explanation of the login command:

mariadb = client command. 

-u user_name = specifies which database user to use.

-p = prompts for a password (more secure than typing it directly in the command).

If you want to connect to a specific database during login, use the following command:

mariadb -u user_name -p database_name

To connect to a remote server, include the host and optionally the port number:

mariadb -u user_name -p -h 192.168.1.100 -P 3306 database_name

A commonly used secure login command is:

mariadb -u root -p

You will then be prompted to enter your password:

root@host:~# mariadb -u root -p
Enter password:

After logging in successfully, you should see output similar to the following:

root@host:~# mariadb -u root -p
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 11.8.6-MariaDB-5 from Ubuntu -- Please help get to 10k stars at https://github.com/MariaDB/Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Bringing It All Together

That’s it. You successfully installed MariaDB on Ubuntu 26.04 OS.

If you have difficulties with this installation, our Linux admins will help you with any aspect. You need to sign up for one of our monthly server management or per-incident server support plans. Do not hesitate to contact us anytime. We are available 24/7.

If you liked this post on how to install MariaDB on Ubuntu 26.04, please share it with your friends on social networks using the buttons on the left, or leave a reply below. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *