This article explains migrating from MySQL database to MariaDB server on Ubuntu 24.04.
MySQL and MariaDB are open-source relational database management systems (RDBMS) that use Structured Query Language (SQL) to manage and query data. MariaDB was forked from MySQL due to concerns about its future under Oracle’s management.
MariaDB is open-source, permitting free usage, modification, and distribution without proprietary restrictions while ensuring compatibility with MySQL.
MariaDB is a direct replacement for MySQL, providing additional features and optimizations such as a wider variety of storage engines, enhanced performance, and improved security.
Backup current database
Before migrating from MySQL to MariaDB, back up your databases; after migration, you need to restore your databases manually.
If you haven’t backed up MySQL databases before, the post below shows you how.
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 migration, conducting a compatibility check is essential to ensure you are upgrading to the latest 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, you can stop using MySQL services and uninstall it from Ubuntu.
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
Since MySQL has been uninstalled, please follow the steps below to install MariaDB.
To install the current version, use its repository config tool from the site 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
Following the steps above, you should have a working MariaDB server instead of MySQL.
To sign on to the MariaDB server, run the command below.
sudo mariadb
That should do it!
Conclusion:
Migrating from MySQL to MariaDB is straightforward when following the correct 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.
Following these steps can help ensure a seamless transition from MySQL to MariaDB, taking full advantage of the enhancements and features offered by the latter.
Leave a Reply