How to Install MariaDB on Ubuntu 26.04, 24.04 and 22.04

Last updated Tuesday, April 28, 2026 7:39 pm Joshua James 8 min read

Ubuntu’s default MariaDB packages are the right starting point when you want a MySQL-compatible database server that stays inside the normal APT update flow. To install MariaDB on Ubuntu, use the repository package for your release, then confirm the service, localhost binding, and root access model before you put applications on it.

The same default-package workflow applies to Ubuntu 26.04 LTS (Resolute Raccoon), Ubuntu 24.04 LTS (Noble Numbat), and Ubuntu 22.04 LTS (Jammy Jellyfish). Ubuntu 26.04 installs MariaDB 11.8.x, Ubuntu 24.04 installs MariaDB 10.11.x, and Ubuntu 22.04 installs MariaDB 10.6.x from the default repositories. Most MySQL clients and many MySQL-targeted applications can connect to MariaDB without changing their connection logic.

Install MariaDB on Ubuntu

The default APT package keeps MariaDB inside Ubuntu’s normal update flow and avoids the extra source-management work of an upstream repository. The default-package path uses Ubuntu repositories only; it does not add the upstream MariaDB APT repository or a Launchpad PPA. If you specifically need a non-default branch, such as MariaDB 11.8 on Ubuntu 24.04 or 22.04, use the separate guide to install MariaDB 11.8 on Ubuntu instead of mixing repository sources inside this default-package workflow.

Ubuntu ReleaseDefault MariaDB PackageArchive ComponentUpstream Community LTS Window
Ubuntu 26.04 LTS (Resolute)MariaDB 11.8.xMainMariaDB 11.8 Community binaries through June 2028
Ubuntu 24.04 LTS (Noble)MariaDB 10.11.xUniverseMariaDB 10.11 through February 2028
Ubuntu 22.04 LTS (Jammy)MariaDB 10.6.xUniverseMariaDB 10.6 through July 2026

These LTS dates come from the MariaDB Server maintenance policy. Ubuntu can package fixes independently from upstream binary timelines, but the support model also depends on the archive component shown in the table. The version map helps explain why search queries for exact branches do not always match the version installed by sudo apt install mariadb-server. On Ubuntu 24.04, for example, the default package is 10.11.x, not 10.6, 11.4, or 11.8.

Ubuntu 24.04 and 22.04 place MariaDB in the universe component. Standard desktop and many server installs already have it enabled, but minimal or customized systems may need to enable Universe on Ubuntu before APT can locate mariadb-server.

Update the APT Package Index

Refresh package metadata before installing MariaDB so APT sees the current candidate for your Ubuntu release.

sudo apt update

These commands use sudo for system-level package management. If your account cannot run sudo commands yet, add an administrator account first or follow the guide to add a user to sudoers on Ubuntu.

Apply pending package upgrades before installing a database server on production systems.

sudo apt upgrade

Install MariaDB Server and Client

Install mariadb-server for the database service and mariadb-client for the terminal client from Ubuntu’s repositories.

sudo apt install mariadb-server mariadb-client

APT initializes the data directory at /var/lib/mysql, writes configuration under /etc/mysql/, and enables the mariadb systemd service during installation.

Verify the MariaDB Version

Check the installed client version to confirm which MariaDB branch your Ubuntu release installed.

mariadb --version

Ubuntu 26.04 returns the 11.8 series from the default repository.

mariadb from 11.8.6-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using  EditLine wrapper

Ubuntu 24.04 returns the 10.11 series, and Ubuntu 22.04 returns the 10.6 series. Use the separate MariaDB 11.8 guide if your application requires the newer upstream LTS branch on those older Ubuntu releases.

Verify the MariaDB Service

Confirm that systemd considers MariaDB active and enabled.

systemctl is-active mariadb
systemctl is-enabled mariadb

A healthy default installation returns:

active
enabled

If either command reports inactive, failed, or disabled, start and enable the service with one command.

sudo systemctl enable --now mariadb

Confirm MariaDB Security Defaults

Older MariaDB tutorials often make mysql_secure_installation the next mandatory step. Current Ubuntu packaging needs a more careful explanation: fresh Ubuntu installs already bind administrative accounts to localhost, create no anonymous users, and omit the old test database. There is no default MariaDB root password on fresh Ubuntu installs; local root access uses sudo and socket authentication instead. Ubuntu 26.04 also does not install the legacy mysql_secure_installation command name; use mariadb-secure-installation only when you intentionally want the legacy interactive review.

Verify Root Access Uses Sudo

Connect as the database root account through sudo. This confirms local administrative access works without storing a separate MariaDB root password.

sudo mariadb -NBe "SELECT CURRENT_USER();"

The result should identify the local root account:

root@localhost

Now try the same database account without sudo.

mariadb -u root -NBe "SELECT 1;"

Ubuntu rejects the non-sudo local root login:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Check for Anonymous Users and Test Database

Confirm that a fresh installation has no anonymous database users.

sudo mariadb -NBe "SELECT COUNT(*) FROM mysql.user WHERE User='';"
0

Check that the legacy test database is also absent.

sudo mariadb -NBe "SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='test';"
0

Use the Current Security Script Name

If you still want to run the interactive hardening script, use the MariaDB command name.

sudo mariadb-secure-installation

Current Ubuntu 24.04 and 22.04 packages keep mysql_secure_installation as a compatibility symlink, but Ubuntu 26.04 does not. Treat mariadb-secure-installation as the portable command across the supported releases.

Manage MariaDB on Ubuntu

Service Management Commands

Use systemd when you need to stop, restart, disable, or re-enable MariaDB.

sudo systemctl stop mariadb
sudo systemctl restart mariadb
sudo systemctl disable mariadb
sudo systemctl enable --now mariadb

Use restart after configuration changes. Ubuntu’s packaged mariadb.service does not expose a systemd reload job, so restart the service instead of trying to reload it.

Update MariaDB Packages on Ubuntu

Normal system upgrades include MariaDB updates when Ubuntu publishes them. To update only installed MariaDB packages, refresh APT metadata and use --only-upgrade so APT does not install MariaDB on systems where it is missing.

sudo apt update
sudo apt install --only-upgrade mariadb-server mariadb-client mariadb-common

This updates the branch already managed by Ubuntu. It does not switch Ubuntu 24.04 from MariaDB 10.11.x to MariaDB 11.8.x; use the separate MariaDB 11.8 repository guide if you intentionally need that branch.

Connect to MariaDB

Open the MariaDB shell as the administrative database user:

sudo mariadb

Type EXIT; or press Ctrl+D to close the session. Create separate database users for applications instead of using root from application code.

Understand MariaDB and MySQL Command Names

The mariadb command is the preferred client name, but Ubuntu also ships mysql as a compatibility symlink for many MySQL-era scripts and examples.

readlink -f /usr/bin/mysql
/usr/bin/mariadb

Use mariadb in new commands, and keep mysql only when an existing script or application explicitly calls that binary name.

Basic Database Operations

The following SQL commands create a database, list databases, switch into the new database, and show the current database selection.

CREATE DATABASE myapp;
SHOW DATABASES;
USE myapp;
SELECT DATABASE();

These commands are intentionally small. Use them to confirm that the server accepts SQL before you connect a web application or import an existing schema.

Next Steps for Web Applications

MariaDB commonly sits behind a web server and PHP runtime. For a LAMP stack, install Apache on Ubuntu and then install PHP on Ubuntu. For a LEMP stack, install Nginx on Ubuntu instead. For browser-based database administration, install phpMyAdmin with Nginx on Ubuntu. For a complete Nginx, MariaDB, PHP, and WordPress deployment, use the guide to install WordPress with Nginx and MariaDB on Ubuntu.

Configure MariaDB Network Access

MariaDB listens only on localhost by default. Keep that setting for single-server LAMP or LEMP stacks where the application and database run on the same host.

Verify Localhost Binding

Check the packaged server configuration for the active bind address. The command uses grep pattern matching to return only the relevant line.

sudo grep -E '^bind-address' /etc/mysql/mariadb.conf.d/50-server.cnf
bind-address            = 127.0.0.1

This output means local applications can connect, but remote machines cannot reach the database listener.

Allow Remote MariaDB Connections

Only allow remote MariaDB access when a separate application server needs it. Restrict the listener and firewall to known hosts instead of exposing port 3306 to the public internet.

Opening MariaDB to a network changes the threat model. Use application-specific database accounts, strong passwords, host-restricted grants, and a firewall rule limited to the application server’s IP address.

Edit the server configuration file:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Set bind-address to a specific private interface address when possible. Use 0.0.0.0 only when the server must listen on all IPv4 interfaces and a firewall will narrow access.

bind-address = 0.0.0.0

Restart MariaDB after changing the bind address:

sudo systemctl restart mariadb

Allow only the application server to reach MariaDB through UFW. Replace 192.168.1.100 with the real source IP address.

sudo ufw allow from 192.168.1.100 to any port 3306 comment 'MariaDB from app server'

The UFW firewall guide for Ubuntu covers rule listing, deletion, and status checks if you need to audit the final firewall state.

Create database users with host restrictions that match your application server instead of allowing every remote host.

CREATE USER 'app_user'@'192.168.1.100' IDENTIFIED BY 'change_this_password';
GRANT ALL PRIVILEGES ON myapp.* TO 'app_user'@'192.168.1.100';
FLUSH PRIVILEGES;

Use database-scoped privileges whenever possible. Broad grants on *.* should be limited to trusted administrative workflows, not application accounts.

Back Up MariaDB Databases

Database backups matter before upgrades, removal, schema changes, and application migrations. MariaDB stores database files under /var/lib/mysql, configuration under /etc/mysql, and service logs commonly under /var/log/mysql.

Check Database Directory Size

Use du to estimate how much storage the database directory currently consumes. The du command examples guide explains additional disk-usage checks.

sudo du -sh /var/lib/mysql
142M    /var/lib/mysql

Create a Logical Backup

A logical backup exports SQL statements that can recreate your databases on the same or a newer compatible MariaDB release.

sudo mariadb-dump --all-databases > "mariadb-all-$(date +%Y%m%d).sql"

The command writes the backup file in your current directory. Keep a copy off the database server, and test restores regularly instead of assuming a backup is usable.

Do not copy /var/lib/mysql while MariaDB is running unless you use a database-aware backup tool. Raw file copies can capture inconsistent table state and fail during restore.

Troubleshoot MariaDB on Ubuntu

Cannot Connect to the Local MariaDB Socket

A stopped service usually produces this socket error:

ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock'

Check the service state first:

systemctl is-active mariadb

If MariaDB is stopped, the command returns:

inactive

Start MariaDB, then verify the service again.

sudo systemctl start mariadb
systemctl is-active mariadb
active

If the service still fails, read the recent MariaDB logs before changing configuration files.

sudo journalctl -u mariadb --no-pager -n 40

Access Denied for Root User

This error is expected when a normal Linux user tries to connect as the database root account without sudo:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Use the local administrative path instead:

sudo mariadb

For applications, create a separate database user with privileges limited to the application’s database.

Port 3306 Is Already in Use

If MariaDB cannot bind to port 3306, check which process owns that listener.

sudo ss -tlnp | grep ':3306'

Relevant output for a normal MariaDB listener looks similar to this, with the process ID varying by system:

LISTEN 0      80         127.0.0.1:3306      0.0.0.0:*    users:(("mariadbd",pid=[varies],fd=[varies]))

If another MySQL-compatible server owns the port, stop that service or move one database server to a different port in its configuration.

Remove MariaDB from Ubuntu

Remove the MariaDB server and client packages when you no longer need the default repository installation. Review APT’s package list before confirming removal on shared systems.

sudo apt remove mariadb-server mariadb-client

Confirm the main packages are no longer installed:

dpkg -l mariadb-server mariadb-client | grep '^ii'

No output means the packages are not in the installed state. If APT reports unused dependencies, preview the cleanup before removing them.

sudo apt autoremove --dry-run

If the preview only lists MariaDB-related packages you no longer need, run the cleanup command without the dry run.

sudo apt autoremove

Use purge only when you also want APT to remove package-managed configuration files.

sudo apt purge mariadb-server mariadb-client mariadb-common

The next command permanently deletes local database files, logs, and any remaining MariaDB or MySQL configuration under /etc/mysql. Back up any databases or configuration files you need first, and do not run it if another MySQL-compatible server on the machine still uses that directory.

After package removal or purge, delete remaining database state only if you want a full reset.

sudo rm -rf /var/lib/mysql /var/log/mysql /etc/mysql

Conclusion

MariaDB is running on Ubuntu with the repository branch that matches your LTS release, a verified local service, and a clear security baseline for root access, localhost binding, backups, and removal. From here, connect it to a web stack by choosing to install Nginx on Ubuntu, install PHP on Ubuntu, or install WordPress with Nginx and MariaDB on Ubuntu.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: