How to Install MariaDB on Ubuntu & Debian

MariaDB is a community-developed, fully open-source fork of MySQL, offering strong compatibility with MySQL-based applications (WordPress, WHMCS, Joomla) plus additional performance features.

Prerequisites

  • Ubuntu 22.04/24.04 or Debian 11/12 VPS
  • Root or sudo access

Step 1 — Update the System

sudo apt update
sudo apt upgrade -y

Step 2 — Install MariaDB

sudo apt install mariadb-server mariadb-client -y

Step 3 — Enable and Start MariaDB

sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo systemctl status mariadb

Step 4 — Secure the Installation

sudo mariadb-secure-installation

Set a strong root password, remove anonymous users, disable remote root login, remove the test database, and reload privileges — recommended for every option.

Step 5 — Log In

sudo mariadb

Step 6 — Create a Database and User

CREATE DATABASE myapp;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'CHANGE_ME_STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON myapp.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Verifying the Installation

mariadb --version

Common Errors

MariaDB won't start:

sudo journalctl -u mariadb

Access denied — verify credentials and that FLUSH PRIVILEGES was run after granting access.

Best Practices

  • Never use the root account for application connections
  • Create a dedicated database and user per application
  • Enable regular automated backups
  • Keep MariaDB updated with regular system updates

FAQ

Can I migrate directly from MySQL to MariaDB?
Generally yes for standard SQL usage — MariaDB maintains strong wire and data-format compatibility, though it's worth testing application-specific queries before switching a production system.

Related Articles

  • How to Install and Secure MySQL 8 on Ubuntu & Debian
  • How to Back Up and Restore MySQL/MariaDB Databases
  • How to Tune MySQL/MariaDB Performance for a VPS
  • mariadb, install mariadb, database, mysql alternative, ubuntu, debian
  • 0 用戶發現這個有用
這篇文章有幫助嗎?

相關文章

How to Install and Secure MySQL 8 on Ubuntu & Debian

MySQL is one of the world's most widely used relational database systems, powering WordPress,...

How to Install PostgreSQL on Ubuntu & Debian

PostgreSQL is an advanced, standards-compliant open-source relational database known for...

How to Install MongoDB on Ubuntu & Debian

MongoDB is a NoSQL, document-oriented database designed for flexibility and horizontal...

How to Install and Secure Redis on Ubuntu & Debian

Redis is a fast, in-memory data store used as a cache, session store, message broker, and queue...

How to Back Up and Restore MySQL/MariaDB Databases

A database is only as safe as its most recent tested backup. This guide covers manual and...