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
- You need a user with
sudorights. If you are logged in asroot, leave outsudo. See create a sudo user. - Update your packages first. See update Linux packages.
- Install either MariaDB or MySQL, not both. Red Hat states that MariaDB and MySQL cannot be installed on the same host because their packages conflict.
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
- Ubuntu / Debian
- AlmaLinux / Rocky
1
Install the package
2
Check that it is running
active (running). Press q to leave.How to install MySQL instead
- Ubuntu
- AlmaLinux / Rocky 9
- AlmaLinux / Rocky 10
How to log in for the first time
On Ubuntu and Debian, the databaseroot account uses socket authentication: it trusts your Linux login, so no password is needed when you use sudo.
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
127.0.0.1 (the server itself) after a fresh install on Ubuntu and Debian. That is the safe default. Check with:
What to do next
- Secure MySQL and MariaDB.
- Create a database and user for each app. Never let apps log in as
root. - 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.Related guides
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:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026