MariaDB started as a fork of MySQL, and the two still share the same wire protocol, the same SQL dialect for most workloads, and the same client tools. That shared history is why you can migrate mysql database to mariadb on a server you already run, without rewriting your app or changing how your code talks to the database. The move itself takes under an hour on a typical small VPS. What takes longer is doing it safely: a full backup first, a version check, a test import, and a way back if anything breaks.
This guide covers the move on Ubuntu and Debian. If you run WordPress, Nextcloud, or any app that stores its data in MySQL, the steps are the same.
Before You Start: Check Versions and Compatibility
MariaDB aims to stay compatible with MySQL, but the two projects have drifted apart over the years. Newer MySQL versions added features MariaDB does not have, and the reverse is also true. Before you touch anything, find out exactly what you run today.
mysql --version mysql -u root -p -e "SELECT VERSION(); SHOW DATABASES;"
As a rough guide, MySQL 5.7 maps well to MariaDB 10.11, and MySQL 8.0 pairs with MariaDB 10.11 or 11.4. These are common pairings, not guarantees. Check the official MariaDB documentation for the version pair you plan to use, and search your schema for features that only exist on one side.
Two checks matter most. First, disk space: a dump plus the new MariaDB data directory needs room, so watch your disk space before it fills up and crashes MySQL. Second, downtime: the database stops while you swap the server packages, so plan a maintenance window and tell your users. If moving the data to a different machine is part of the plan, read our guide on how to move a MySQL database to a bigger VPS first.
Step 1: Back Up Everything with mysqldump
Do not skip this step. A mysqldump backup before migration is the only thing standing between a failed import and lost data. Take a full logical backup of every database, including the system databases that hold users and grants.
sudo mysqldump -u root -p --all-databases --routines --events --single-transaction > /root/mysql-full-backup-$(date +%F).sql
The flags matter. --routines and --events include stored procedures, functions, and scheduled events that a plain dump leaves behind. --single-transaction gives InnoDB tables a consistent snapshot without locking them, so a live site keeps serving traffic while the dump runs.
When the dump finishes, check that it is real and complete. Look at the file size and confirm the backup holds your largest tables.
ls -lh /root/mysql-full-backup-*.sql tail -5 /root/mysql-full-backup-*.sql grep -c "CREATE TABLE" /root/mysql-full-backup-*.sql
Copy the file off the server too. A backup that lives only on the machine you are about to change is not a backup. Send it to another VPS, your laptop, or object storage. If you want this to happen on its own from now on, automate mysqldump backups with cron.
Step 2: Remove MySQL and Install MariaDB
Stop MySQL first, then remove its server packages. Keep the data directory in place for now. A clean import from your dump is the safer path, so you will remove the old data directory after the backup is verified.
sudo systemctl stop mysql sudo apt remove --purge mysql-server mysql-client mysql-common sudo apt autoremove sudo apt update sudo apt install mariadb-server mariadb-client
If you need a newer release than your distro ships, add the official MariaDB repository first, then install. Either way, check which version landed before you go further.
sudo systemctl start mariadb sudo systemctl enable mariadb mariadb --version
Run the included security script to set a root password, remove anonymous users, and drop the test database. Answer yes to each prompt unless you have a reason not to.
sudo mariadb-secure-installation
How to Migrate a MySQL Database to MariaDB Step by Step
With MariaDB running and empty, import the dump you made in step 1. This is the core of the mysql to mariadb migration: the same SQL that MySQL wrote out gets replayed into MariaDB, recreating databases, tables, users, and grants.
sudo mariadb -u root -p < /root/mysql-full-backup-YYYY-MM-DD.sql
Replace the date with the actual filename. For a large database the import can take a while. If your SSH session might drop, run it inside tmux or screen.
After the import, run the upgrade tool. It checks every table, updates system tables to the MariaDB format, and flags tables that need attention.
sudo mariadb-upgrade -u root -p
Older MariaDB releases shipped this tool as mysql_upgrade. If your version still uses that name, the command is the same apart from the name. Then restart MariaDB so it picks up any changes cleanly.
sudo systemctl restart mariadb sudo systemctl status mariadb
Step 4: Verify the Migration Worked
An import that exits with no error is not proof that everything moved. Compare the new server against your notes from the old one, database by database.
mariadb -u root -p -e "SHOW DATABASES;" mariadb -u root -p -e "SELECT table_schema, COUNT(*) FROM information_schema.tables GROUP BY table_schema;"
Pick your largest database and compare table counts and row counts with the numbers from MySQL before the move. If you did not record them, your dump file still holds the truth: count the CREATE TABLE statements and compare.
Check the users and grants too. Log in as your application user and confirm it can read and write.
mariadb -u root -p -e "SELECT User, Host FROM mysql.user;" mariadb -u appuser -p -e "SHOW GRANTS;"
Step 5: Point Your Apps at MariaDB and Test
Most apps need no config change at all. MariaDB listens on the same socket and port, uses the same default credentials, and answers the same client libraries. WordPress, for example, keeps working with the same wp-config.php. Restart your web server and PHP-FPM so any lingering connections reset.
sudo systemctl restart nginx php8.3-fpm
Adjust the PHP version in that command to match what your server runs. Then click through the app yourself: log in, load the busiest pages, submit a form, and check that writes land in the database. Watch the error log for the first hour after the switch.
If your app reports an error establishing a database connection, the cause is almost always one of three things: MariaDB is not running, the app user lost a grant in the import, or the socket path changed. Check each in that order before changing config files.
How to Roll Back If Something Goes Wrong
A migration plan without a rollback plan is a gamble. Decide your rollback trigger before you start: if the import errors out, if row counts do not match, or if the app throws database errors after the switch, stop and roll back instead of patching things live.
Rollback is straightforward because you kept the dump. Stop MariaDB, remove its packages and data directory, reinstall MySQL, and import the same dump back.
sudo systemctl stop mariadb sudo apt remove --purge mariadb-server mariadb-client sudo rm -rf /var/lib/mysql sudo apt install mysql-server sudo mysql -u root -p < /root/mysql-full-backup-YYYY-MM-DD.sql
Keep the dump until the new setup has run without trouble for at least a week. For WordPress sites, set up daily database backups for WordPress once MariaDB is live, so the next change starts from a backup that already exists.
Common Problems After the Switch
Most migrations go through cleanly, but a few issues show up often enough to know in advance.
Authentication plugin errors. MySQL 8 defaults to caching_sha2_password, while older clients expect mysql_native_password. MariaDB handles both, but an app built against an old client library can still fail to log in. Create or alter the user with the plugin the client supports, or update the client library.
Missing tables after import. This usually means the dump itself was cut short, often by a full disk. Check the tail of the dump file for a completion marker before you blame MariaDB.
Slower queries than before. MariaDB and MySQL share an optimizer lineage but not identical query plans. Run ANALYZE TABLE on your largest tables after the import so the optimizer has fresh statistics.
Character set surprises. If text shows as question marks or odd symbols, check that the dump, the connection, and the tables all agree on utf8mb4. A dump taken with the wrong default character set garbles data on import. Re-dump with --default-character-set=utf8mb4 rather than patching rows after the fact.
MariaDB vs MySQL compatibility is close enough that most small and mid-size apps move over without code changes. The work that matters is not the install command. It is the backup, the version check, the row-count comparison, and the rollback plan. Get those four right and the migration is a routine maintenance task instead of a late-night emergency.