Migrate MySQL to MariaDB on Ubuntu 24.04
You migrate MySQL to MariaDB on Ubuntu 24.04 to leverage MariaDB’s open-source advantages and improved features.
MariaDB is a community-developed database system, a derivative of MySQL designed for compatibility while offering enhanced performance and additional storage engines.
This process is popular because MariaDB provides a robust, free alternative to MySQL, often outperforming it and including features like Percona XtraDB Cluster.
You’ll move your data seamlessly to MariaDB, ensuring its integrity and keeping system downtime to a minimum with a structured approach.
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
Before you migrate MySQL to MariaDB, it’s super important to back up all your current databases. You’ll need these backups to put your data back after the move. Also, make a copy of your main MySQL settings file just in case.
If you’re new to backing up MySQL databases, the linked post below will guide you through the process.
As a precaution, back up the main MySQL configuration file to your home directory.
sudo cp /etc/mysql/my.cnf ~/my.cnf
After backing up MySQL database(s), continue below.
Verify MySQL and MariaDB compatibility
Before you begin, it’s important to check compatibility. This ensures you’re upgrading to the right version of MariaDB.
Below is a table that illustrates the compatibility between different versions of MySQL and MariaDB.
| 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 | – |
Continue below if everything is good.
Stop and Uninstall MySQL from Ubuntu
Now it’s time to stop and remove MySQL from your Ubuntu system. First, run the command to stop any running MySQL services. Then, use the commands provided to completely uninstall MySQL and clean up any leftover files and user accounts.
Run the command below to stop MySQL services.
sudo systemctl stop mysql
Next, remove MySQL stuff and the user from Ubuntu by running the command below.
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
MySQL should be uninstalled.
Install MariaDB
With MySQL removed, you can now install MariaDB. To get the latest version, visit the MariaDB repository config tool website. There, you’ll choose the right version and repository for Ubuntu, and get the GPG key needed to install MariaDB version 10.
To install the latest version, head to the MariaDB repository config tool site linked below.
Choose the correct version and repository to install MariaDB version 10 on Ubuntu. Use the GPG key provided below for the repository.
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'
Then, create a repository file for MariaDB by running the command below.
sudo nano /etc/apt/sources.list.d/mariadb.sources
Copy the content below into the file.
# 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 and exit.
Next, run the command below to update the Ubuntu package index and install MariaDB 10.
sudo apt update
sudo apt install mariadb-server
After installing the MariaDB server, restore the main configuration file backed up above.
sudo cp ~/my.cnf /etc/mysql/
Then, start and enable its services.
sudo systemctl start mariadb
Finally, restore the databases backed up previously to the new MariaDB server.
Learn how to restore MariaDB using the post below.
Restore the MariaDB database on Ubuntu
By following these steps, you’ll have a smooth transition to MariaDB and can start enjoying all its extra features and improvements.
To sign on to the MariaDB server, run the command below.
sudo mariadb
That should do it!
Conclusion:
Migrating from MySQL to MariaDB is smooth sailing when you follow these steps. Here are the key takeaways:
- Backup Important Data: Always ensure you have a complete backup of your databases and configuration files before starting the migration.
- Compatibility Check: Verify the compatibility between your MySQL version and the MariaDB version to avoid potential issues.
- Uninstall MySQL: Completely remove MySQL from your system to prepare for the installation of MariaDB.
- Install MariaDB: Use the official repository to install the most recent version of MariaDB on your Ubuntu system.
- Restore Backups: After installation, restore your databases to the new MariaDB server to regain access to your data.
- Test Functionality: Once migrated, log into MariaDB and perform checks to ensure everything functions correctly.
By following these steps, you’ll have a smooth transition to MariaDB and can start enjoying all its extra features and improvements.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!