Skip to main content
To install MariaDB on Ubuntu or Debian, run sudo apt update and then sudo apt install mariadb-server. On AlmaLinux or Rocky Linux, run sudo dnf install mariadb-server and start it with sudo systemctl enable --now mariadb. Log in with sudo mariadb. For Oracle MySQL on Ubuntu, install mysql-server instead and log in with sudo mysql.

Before you start

Which should I use, MariaDB or MySQL?

A database server stores the data for websites and apps, such as WordPress posts or game plugin stats. MariaDB started as a fork of MySQL and uses the same commands, the same port (3306) and the same client tools, so most software that “needs MySQL” works with either. Pick MariaDB if you have no reason to choose otherwise. Debian ships MariaDB as its database server. Pick MySQL if your software’s documentation asks for MySQL 8 specifically.

Which version will I get?

Sources: Debian 13 release notes, Red Hat Enterprise Linux 10 database servers.

How to install MariaDB

1

Install the package

The service starts by itself after installation.
2

Check that it is running

Look for active (running). Press q to leave.

How to install MySQL instead

How to log in for the first time

On Ubuntu and Debian, the database root account uses socket authentication: it trusts your Linux login, so no password is needed when you use sudo.
For MySQL on Ubuntu, use sudo mysql. Ubuntu documents that MySQL’s root account “authenticates with auth_socket”. MariaDB’s packages work the same way: the MariaDB documentation says root signs in through Unix socket authentication. You see a prompt such as MariaDB [(none)]>. Type exit to leave. If you installed MySQL on AlmaLinux or Rocky, run sudo mysql_secure_installation next. Red Hat’s MySQL guide uses this script to set the root password.

How to check it worked

Expected output on Ubuntu 24.04:
The server only listens on 127.0.0.1 (the server itself) after a fresh install on Ubuntu and Debian. That is the safe default. Check with:
Do not open port 3306 to the whole internet. If an app on another machine needs the database, follow allow remote MySQL connections and only allow that machine’s IP address.

What to do next

  1. Secure MySQL and MariaDB.
  2. Create a database and user for each app. Never let apps log in as root.
  3. Set up backups before you store real data.

Frequently asked questions

Is MariaDB a drop-in replacement for MySQL?

For most web apps, yes. MariaDB uses the same protocol, port and SQL for everyday tasks. Some newer MySQL 8 features are not in MariaDB, so check your app’s requirements if it names a specific MySQL version.

Why does mysql -u root -p say “Access denied” right after install?

On Ubuntu and Debian, root logs in through the Linux socket, not a password. Run sudo mariadb or sudo mysql instead.

Can I install MariaDB and MySQL on the same server?

No. The packages conflict. If you need both, run one of them in a container. See install Docker.

How much RAM does MariaDB need?

It depends on the size of your data and how many connections your apps open. Watch usage with check memory usage and add swap space on small plans.

VPS and dedicated server guides

Every guide in this section.

Secure MySQL and MariaDB

Run the secure installation script.

Create a database and user

Give each app its own login.

Install a LEMP stack

Nginx, PHP and MariaDB together.

Install phpMyAdmin

Manage databases in the browser.

Checked against the official Ubuntu Server documentation, Red Hat database server guides and MariaDB documentation on 4 November 2026; install and login commands tested on Ubuntu 24.04 LTS with MariaDB 10.11. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026