ItsmeITItsmeIT
  • Linux
    • Debian
    • Ubuntu
  • PC/Windows
Reading: How to Install MariaDB on Ubuntu 22.04/24.04 LTS
Share
Notification Show More
Font ResizerAa
ItsmeITItsmeIT
Font ResizerAa
  • Categories
    • Linux
    • Debian
    • Ubuntu
    • PC/Windows
Have an existing account? Sign In
Follow US
© 2025 ItsmeIT. All rights reserved.

Home » Linux » Ubuntu » How to Install MariaDB on Ubuntu 22.04/24.04 LTS

How to Install MariaDB on Ubuntu 22.04/24.04 LTS

avatar
By
Loibv
avatar
ByLoibv
The ItsmeIT team – delivering cutting-edge updates, tech trends, and insider knowledge from the world of technology.
Follow:
Last updated: August 26, 2025

MariaDB is a high-performance, open-source relational database management system (RDBMS) designed to be fully compatible with MySQL. It is widely used in web applications, software development, and enterprise solutions. This guide walks you through installing and securing MariaDB on Ubuntu 22.04/24.04 LTS efficiently.

install MariaDB Ubuntu
Install MariaDB on Ubuntu: A Step-by-Step Guide

Why Choose MariaDB Over MySQL?

  • Faster Performance: MariaDB outperforms MySQL in many use cases, especially for read-heavy workloads. Benchmark tests show MariaDB can handle up to 40% more queries per second than MySQL under similar conditions.
  • Full MySQL Compatibility: If you’re migrating from MySQL, MariaDB works as a drop-in replacement, supporting the same commands, clients, and connectors.
  • Active Development & Open Source: Unlike MySQL (now owned by Oracle), MariaDB is maintained by an open-source community, ensuring continuous improvements and transparency.
  • More Storage Engines & Advanced Features: MariaDB includes extra storage engines like Aria, TokuDB, and MyRocks, which are not available in MySQL.

Install MariaDB

These steps will install the latest stable version compatible with your system. If you want to install a specific version or try the newest release, refer to the official MariaDB documentation.

Step 1: Update Your System

Before installing MariaDB, update your package lists to ensure you get the latest version:

sudo apt update

Step 2: Install MariaDB

Run the following command to install MariaDB:

sudo apt install mariadb-server -y

Once installed, verify the installation with:

mariadb --version

Step 3: Secure the MariaDB Installation

By default, MariaDB comes with some insecure settings. Secure it using:

sudo mysql_secure_installation

This script will guide you through:
✅ Setting a root password (MariaDB 10.4+ uses Unix socket authentication, so this may be optional).
✅ Removing anonymous users to prevent unauthorized access.
✅ Disabling remote root login for security.
✅ Deleting the test database that comes pre-installed.

Screenshot step:

config mariadb

Step 4: Verify MariaDB is Running

Ensure MariaDB is active and starts on boot:

sudo systemctl enable mariadb

Check the status:

sudo systemctl status mariadb

If MariaDB is running correctly, you should see output like: Active: active (running) since …

Step 5: Connect to MariaDB

To access the MariaDB shell, use:

sudo mysql

or, if a password is required:

sudo mysql -u root -p

Once inside the MariaDB shell, verify that databases are working by running:

SHOW DATABASES;

Step 6: Create a Database and User

To create a database and a new user with full privileges, run:

CREATE DATABASE my_database;
CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';
FLUSH PRIVILEGES;
exit;

Common Installation Issues & Fixes

Issue: Can’t Connect to MariaDB (Socket Error)

If you see an error like: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

Try restarting the service:

sudo systemctl restart mariadb

Or check for missing MariaDB directories:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo systemctl restart mariadb

Issue: MariaDB Conflicts with MySQL

If MySQL is installed on your system, it may conflict with MariaDB. Remove MySQL first:

Note: Backup your data before deleting anything. If you’re doing a fresh installation and don’t have important data, feel free to wipe everything and start over—it will be easier than troubleshooting errors.

1️⃣ Stop MySQL and Remove It

sudo service mysql stop
sudo apt purge 'mysql*' mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
sudo apt remove 'mysql*' && sudo apt autoremove && sudo apt autoclean
sudo rm -rf /etc/mysql /var/log/mysql

2️⃣ Backup /var/lib/mysql Before Removing MySQL (If Needed)

Before removing MySQL, check if you have important databases in /var/lib/mysql. If yes, back them up to avoid data loss:

sudo systemctl stop mysql
sudo cp -r /var/lib/mysql /var/lib/mysql_backup_$(date +%F

If you’re setting up MariaDB from scratch and don’t have any important data, you can remove MySQL without backing up. In that case, just delete /etc/mysql instead of wiping everything:

sudo rm -rf /etc/mysql

3️⃣ Install MariaDB

Now, proceed with installing MariaDB as per Step 2.

You have successfully installed and secured MariaDB on Ubuntu 22.04/24.04 LTS! Now, you can create databases, manage users, and optimize performance.

Share This Article
Facebook Reddit Telegram Threads
avatar
ByLoibv
Follow:
The ItsmeIT team – delivering cutting-edge updates, tech trends, and insider knowledge from the world of technology.
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

Most Popular

install wordpress nginx
How to Install WordPress on Ubuntu 22.04/24.04 with Nginx, MariaDB, PHP8.2 (LEMP)
Scan Virus Ubuntu
3 Best Ways to Detect and Remove Malware on Ubuntu/Linux
boot virtualbox from usb
How to Boot from USB in VirtualBox on Ubuntu/Linux
Install SSL Localhost Ubuntu
How to Install SSL on Localhost in Ubuntu / Linux?
fix login error Gnome Online Accounts Ubuntu 22.04
How to Fix GNOME Online Accounts Login Issues on Ubuntu 22.04
Previous Next
ItsmeITItsmeIT
Follow US
© 2025 ItsmeIT. All Rights Reserved.
  • Privacy Policy
  • Terms of Service
Logo ItsmeIT logo
Welcome Back!

Sign in to your account

Continue with Google
Register   |Lost your password?