On this page
- What MariaDB version comes with each distribution?
- How do you install MariaDB from distro packages?
- How do you install a newer release from the MariaDB repository?
- How do you secure MariaDB after installing it?
- How do you add a database and user for an application?
- How should you size MariaDB memory?
- How do you upgrade MariaDB between major releases?
- What should you check when MariaDB does not start?
- Questions
What MariaDB version comes with each distribution?
Every supported system ships a long-term release, so the distro package is a sound default for most sites. Ubuntu 24.04 and Debian 12 carry 10.11, Ubuntu 22.04 carries 10.6, Debian 13 carries 11.8 and Rocky Linux 9 or AlmaLinux 9 install 10.5 from AppStream unless you choose a newer stream.
Reach for the MariaDB repository when an application asks for features from 11.x, when you want the same version on servers that run different distributions, or when the AppStream build on Rocky and Alma feels too old. Check what your system offers before you decide:
apt policy mariadb-server # Ubuntu, Debian
dnf info mariadb-server # Rocky, AlmaMariaDB speaks the MySQL protocol and accepts most MySQL SQL, which is why so many PHP applications list it as a supported backend. It is a separate project, though, and the two have drifted apart in areas such as JSON storage and authentication plugins, so do not run both on one server. If you need Oracle MySQL specifically, follow the MySQL 8 guide instead.
How do you install MariaDB from distro packages?
One package install is enough; on Debian and Ubuntu the service starts right away, while on Rocky and Alma you enable it yourself.
Ubuntu and Debian
sudo apt update
sudo apt install -y mariadb-server mariadb-client
sudo systemctl status mariadb --no-pager
mariadb --versionRocky Linux and AlmaLinux
sudo dnf install -y mariadb-server
sudo systemctl enable --now mariadb
mariadb --versionThe client binary is called mariadb; the old mysql name still works as a symlink on current packages, but newer releases print a warning when you use it, so get used to the new name in scripts.
How do you install a newer release from the MariaDB repository?
Run the repository setup script with the release you want, then install the server package. The script adds the signing key and a repo file for your exact distribution.
curl -LsSO https://r.mariadb.com/downloads/mariadb_repo_setup
sha256sum mariadb_repo_setup # compare with the checksum on the MariaDB download page
chmod +x mariadb_repo_setup
sudo ./mariadb_repo_setup --mariadb-server-version="mariadb-11.8"On Ubuntu and Debian continue with sudo apt update and sudo apt install -y mariadb-server. On Rocky and Alma the packages from this repository use capital letters:
sudo dnf install -y MariaDB-server MariaDB-client
sudo systemctl enable --now mariadbThe 11.4 and 11.8 lines are both long-term releases. Stick to an LTS line on a server you do not want to touch often; short-term releases change faster and reach end of life within about a year.
How do you secure MariaDB after installing it?
Run the secure installation helper, keep the default unix_socket login for root and remove the sample accounts and database.
sudo mariadb-secure-installationWhen the helper asks whether to switch root to unix_socket authentication, answering yes (or keeping it if already set) means only the Linux root user can become MariaDB root through sudo mariadb. There is no root password to steal or brute-force over the network. Say yes to removing anonymous users, disabling remote root login and dropping the test database.
Then confirm where the server listens:
sudo ss -ltnp | grep 3306Debian and Ubuntu packages bind to 127.0.0.1 by default through /etc/mysql/mariadb.conf.d/50-server.cnf. On Rocky and Alma, add bind-address = 127.0.0.1 under [mysqld] in /etc/my.cnf.d/mariadb-server.cnf (or server.cnf with the MariaDB repository build) and restart with sudo systemctl restart mariadb. Keep port 3306 closed in UFW or firewalld.
How do you add a database and user for an application?
Create the database with a full Unicode character set, then a user that can only reach that one database.
sudo mariadb
CREATE DATABASE blog CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'blog'@'localhost' IDENTIFIED BY 'Another-Long-Passphrase-7';
GRANT ALL PRIVILEGES ON blog.* TO 'blog'@'localhost';
FLUSH PRIVILEGES;
EXIT;Confirm the account logs in over TCP, which is how most applications connect:
mariadb -u blog -p -h 127.0.0.1 blog -e 'SELECT USER(), VERSION();'For an administrator who prefers a GUI, keep the server local and forward the port with ssh -N -L 3307:127.0.0.1:3306 deploy@198.51.100.24, then point the desktop client at 127.0.0.1 port 3307. The SSH tunnel guide covers this in detail. Web-based tools are another option; Adminer is a single file that works well behind HTTPS and a password.
How should you size MariaDB memory?
Set innodb_buffer_pool_size to roughly half of RAM when the web stack shares the server, and add the slow query log so you can see which queries need work.
Put your settings in their own file so upgrades leave them alone, such as /etc/mysql/mariadb.conf.d/90-tuning.cnf on Debian and Ubuntu or /etc/my.cnf.d/90-tuning.cnf on Rocky and Alma:
[mysqld]
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
max_connections = 120
slow_query_log = 1
long_query_time = 1
log_slow_query_file = /var/log/mysql/mariadb-slow.logOn Rocky and Alma, create the log directory first with sudo install -d -o mysql -g mysql /var/log/mysql. Restart and check that the values took effect:
sudo systemctl restart mariadb
sudo mariadb -e "SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size';"Avoid copying large tuning templates from forums. Each connection also reserves buffers, so a very high max_connections on a small plan can push the server into swap. Watch memory with the tools in usage monitoring after any change.
How do you upgrade MariaDB between major releases?
Take a logical dump, switch the repository to the new series, upgrade the packages and let the server finish its schema upgrade.
sudo mariadb-dump --all-databases --routines --events --single-transaction | gzip > all-$(date +%F).sql.gz
sudo ./mariadb_repo_setup --mariadb-server-version="mariadb-11.8"
sudo apt update && sudo apt full-upgrade # or: sudo dnf upgrade MariaDB-server
sudo systemctl restart mariadb
sudo mariadb-upgradeCurrent packages run the upgrade step automatically on start, and the last command simply reports that nothing is left to do. Go one long-term release at a time (for example 10.11 to 11.4 to 11.8) on large databases, and read the release notes for removed options before you restart, because a removed option in a config file stops the server from starting. Plan your dumps with the backup and restore guide.
What should you check when MariaDB does not start?
Read the journal and the error log first; they almost always name the file and line that caused the failure.
sudo journalctl -u mariadb -n 60 --no-pager
sudo tail -n 60 /var/log/mysql/error.log # Debian, Ubuntu when logging to a file
df -h /var/lib/mysql
free -mTypical causes are an unknown option after an upgrade, a buffer pool bigger than available memory, a full disk and wrong ownership on /var/lib/mysql after a manual restore (fix with sudo chown -R mysql:mysql /var/lib/mysql). If tables report corruption after a crash, repairing a crashed table walks through the checks.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Install MariaDB
Is MariaDB a drop-in replacement for MySQL?
For most web applications such as WordPress, Nextcloud and many PHP frameworks, yes. Newer MySQL-only features, for example some JSON functions and the 8.x data dictionary details, differ, so test before moving an existing MySQL 8 database.
Which command replaces mysql_secure_installation?
Use mariadb-secure-installation. The old name may still exist as a link on some systems, but the new name is the one maintained going forward.
Why does sudo mariadb log me in without a password?
Root uses the unix_socket plugin, so the operating system vouches for you. Only users who can run commands as Linux root get in that way, and remote password attacks against the root account cannot work.
Should I use the distro package or the MariaDB repository?
Use the distro package unless you need a newer feature or matching versions across servers. Distro packages get security updates through your normal system updates with no extra repo to manage.
How do I let a second server use this database?
Prefer an SSH tunnel or a WireGuard link between the two servers. If you open port 3306, allow only that one source address in the firewall and create the user with that address as its host part.
More in Databases
- Install MySQL 8
- Install PostgreSQL
- Install MongoDB
- PostgreSQL JSON, arrays and special types
- PostgreSQL views, triggers and CTEs
- PostgreSQL full-text search and encryption
- MySQL keys, indexes and full-text search
- MySQL JSON, views and stored procedures
- Apache Solr search server
- Install Redis or Valkey
- Install Memcached
- Apache Cassandra cluster
- Install Apache CouchDB
- InfluxDB for time series
- Install Elasticsearch
- Back up and restore MySQL and MariaDB
- Back up and restore PostgreSQL
- MySQL users, roles and passwords
- PostgreSQL roles and permissions
- Repair a crashed MySQL table
- PostgreSQL streaming replication
- MongoDB replica set
- PostGIS for location data
- Database insight with PgHero
- Couchbase Server
- ArangoDB multi-model database
- Remote database access over SSH