Migrate MySQL to MariaDB on Ubuntu 24.04
Migrating MySQL to MariaDB on Ubuntu 24.04 swaps your database server for MariaDB, which is a fork of MySQL. Many people make the switch for performance, extra storage engines, or because they prefer MariaDB’s community-driven development. MariaDB acts as a drop-in replacement for MySQL in most setups, so your tables and queries keep working after the switch. Check your own schemas anyway. Newer MySQL 8 features, such as some JSON behaviour and the default authentication plugin, don’t always match MariaDB.
Ubuntu 24.04 handles the change through its package manager. The method here is a dump and restore. You export your data, remove the MySQL packages, install MariaDB and import the data again. Because the data lives in your exports, it stays safe throughout. Plan a maintenance window, because the database is offline while you do this. You need a user with sudo rights and a terminal.
Stop and uninstall MySQL using `systemctl stop mysql`, `apt-get remove`, and `deluser mysql`. Install MariaDB from its official repository using `apt install mariadb-server`. Restore your backed-up databases to complete the migration.
Backup current database
Back up your current database before you migrate from MySQL to MariaDB. If anything goes wrong during the switch, this backup is your only way back. Export every active database, and copy your main configuration file to your home directory before you remove any software from Ubuntu.
Don’t skip this step, even on a test server. The uninstall step later removes packages and can delete data files, so assume nothing in the old data directory survives.
Follow the linked guide below for the full database export instructions. Export all databases, not just the ones you use every day. Make sure the dump files end up somewhere that survives the migration, such as your home directory or another machine.
Copy the active configuration file to your home directory as a safety net. You may want your old settings later, for example buffer sizes, character sets or the bind address. Run the command shown below in the terminal. If it reports a permission error, run it again with sudo.
sudo cp /etc/mysql/my.cnf ~/my.cnf
Check that the export files and the configuration copy exist and are not empty before you go on. A dump file of 0 bytes means the export failed. Finish the exports completely before the next phase begins.
Verify MySQL and MariaDB compatibility
Next, check compatibility. Confirm that the MariaDB release you plan to install supports your databases and configuration. Start by finding out which MySQL version you run now. Ubuntu 24.04 ships MySQL 8.0 in its own repositories, so that is the most likely starting point.
Differences are most likely in newer features, such as the JSON data type, authentication plugins, collations and some system variables. If your applications use any of these, test the restore on a spare machine first.
Review the version matrix below before you continue. Find your MySQL version in it and check which MariaDB versions are listed as compatible with it.
| MySQL | MariaDB |
| 5.1 | 5.1, 5.2, 5.3 |
| 5.5 | 5.5 |
| 5.6 | 10.0, 10.1 |
| 5.7 | 10.2, 10.3, 10.4, 10.5 |
| 8.0 | – |
Go on to the software removal only when the version checks pass. If your MySQL version is not covered by the matrix, stop here and test on a copy of the server before you touch production.
Stop and Uninstall MySQL from Ubuntu
Stopping and uninstalling MySQL removes the old database software, so it can’t conflict with MariaDB. Stop the running MySQL service first, then purge the old packages from the terminal. Do both before you install MariaDB.
Make sure your backups are complete before you run the commands below. Purging packages can remove data that cannot be recovered.
Run the command below to stop the active MySQL processes. Once it finishes, the database is offline and any application that depends on it will start to show connection errors. That is expected during the migration.
sudo systemctl stop mysql
Purge the remaining MySQL packages and their associated user accounts from the system. The terminal may ask you to confirm. Read the list of packages it plans to remove before you answer, and check that nothing unrelated is on it.
sudo apt-get remove mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
When the command finishes without errors, the system cleanup is complete and MySQL is gone. The server is now ready for MariaDB.
Install MariaDB
Installing MariaDB with the newest packages means adding the official repository and its signing key to your system first. Configure the official source list in your terminal so the package manager downloads the version you picked. Without it, Ubuntu installs whichever MariaDB version is in its own archive, which may be older.
Open the official repository configuration page, linked below. Choose Ubuntu 24.04 and the MariaDB version you want, and use the values it shows you.
Download the GPG key for the repository. A GPG key is a digital signature that lets your system verify the packages really come from MariaDB. Then create a new source file for MariaDB with the commands below.
sudo apt install apt-transport-https curl
sudo mkdir -p /etc/apt/keyrings
sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
Open the new source file in a terminal editor to write the repository definitions. Use the command below. Because the file sits in a system location, the command needs sudo.
sudo nano /etc/apt/sources.list.d/mariadb.sources
Paste the configuration block into the file. A typo here will make the package update fail later, so check that the version number and the Ubuntu release name match what the repository page showed.
# MariaDB 10.11 repository list - created 2025-03-21 17:45 UTC
# https://mariadb.org/download/
X-Repolib-Name: MariaDB
Types: deb
# deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# URIs: https://deb.mariadb.org/10.11/ubuntu
URIs: https://mirrors.accretive-networks.net/mariadb/repo/10.11/ubuntu
Suites: noble
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
Save the changes and close the editor. The exact key combination depends on the editor you opened. In nano, you save and then exit. You return to the normal terminal prompt.
Refresh the package indexes, then install the database server. The refresh should list the new MariaDB repository among its sources without any errors. The install then downloads MariaDB and starts it.
sudo apt update
sudo apt install mariadb-server
Restore the configuration file you saved earlier to the system path. Compare it with the new default file before you overwrite anything. Settings written for MySQL may refer to options MariaDB doesn’t support, and an unknown option can stop the server from starting.
sudo cp ~/my.cnf /etc/mysql/
Start the database service and enable it, so it also starts automatically at boot. If the service fails to start, the usual cause is an option in the restored configuration file that MariaDB does not recognise. Remove that option and try again.
sudo systemctl start mariadb
Import your archived database dumps back into the running MariaDB server. Restore each database you exported earlier, and keep the original dump files until the checks at the end are done.
Follow the restoration tutorial below for the import instructions.
Restore the MariaDB database on Ubuntu
With these steps done, you have a clean MariaDB server holding your data. Verify it before you point production applications at it.
Log into the SQL shell to check that the database is reachable. Once you are in, list your databases and confirm every one you restored is there. Open a few tables and run a simple query against them. If you can see your data, the login works and the import succeeded.
sudo mariadb
If the databases and tables show up as expected, the deployment is finished. Then restart your applications and watch their logs for connection or authentication errors.
Conclusion:
Migrating database platforms on Ubuntu 24.04 pays off in the long run when you do it methodically. The key points to remember are:
- Backup Important DataAlways ensure you have a complete backup of your databases and configuration files before starting the migration. Check that the dump files are not empty.
- Compatibility CheckVerify the compatibility between your MySQL version and the MariaDB version to avoid potential issues. Pay attention to newer MySQL 8 features.
- Uninstall MySQLCompletely remove MySQL from your system to prepare for the installation of MariaDB. Stop the service first, then purge the packages.
- Install MariaDBUse the official repository to install the most recent version of MariaDB on your Ubuntu system. Add the signing key first so packages can be verified.
- Restore BackupsAfter installation, restore your databases to the new MariaDB server to regain access to your data. Keep the original dumps until you have tested.
- Test FunctionalityOnce migrated, log into MariaDB and perform checks to ensure everything functions correctly. Then confirm your applications connect without errors.
Once the migration is done, you run a faster, robust database engine backed by active community development, and you have a tested backup of the old data if you ever need to compare or roll back.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!