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.

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:

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.
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/lib/mysql /var/log/mysql
Then, reinstall 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.