How to Migrate from MySQL 5.7 to MariaDB 10.5 on Ubuntu 18.0

How to Migrate from MySQL 5.7 to MariaDB 10.5 on Ubuntu 18.04

If you’re running MySQL 5.7 on Ubuntu 18.04 and want to switch to MariaDB 10.5, you’re in the right place.

Ubuntu 18.04 ships MySQL 5.7 and MariaDB 10.1 in its default repos. So if you want MariaDB 10.5, you can’t just hit apt install and call it a day—you need to:

  • Remove MySQL first
  • Add the MariaDB 10.5 repository
  • Install MariaDB and check your data

Let’s walk through it step by step so you don’t lose your databases in the process.

1. Know What You’re Running (Check MySQL Version)

Before touching anything, confirm what’s installed on your box.

Run this in your terminal:

mysql --version

You should see something like:

mysql  Ver 14.14 Distrib 5.7.33, for Linux (x86_64) using  EditLine wrapper

That tells you MySQL 5.7.33 is currently installed.

Why this matters: it’s a quick sanity check so you’re sure you’re migrating from the expected version, and also helpful later if you’re comparing behavior before/after.

2. Backup Your Databases (Do Not Skip This)

Before you uninstall MySQL, you must back up your databases.

Even if you’re confident, even if this is “just dev” – backups are your safety net.

Here’s an example backing up a database named wordpress:

mysqldump -u root -p wordpress > wordpress_backup.sql
  • -u root → use MySQL root user (adjust if you use a different admin user)
  • -p → will ask your MySQL password
  • wordpress → the database name you want to back up
  • wordpress_backup.sql → output file containing the SQL dump

Repeat for other important databases as needed, changing the database and file name.

Store these .sql files somewhere safe, preferably not in /tmp or any folder that’s frequently cleaned up.

Why this matters: when you remove MySQL, you don’t want any surprise data loss. With dumps, you can always restore into MariaDB later if something goes wrong.

3. Stop and Uninstall MySQL 5.7

Now that you have backups, you can safely remove MySQL.

First, stop the MySQL service so nothing is writing while you uninstall:

sudo systemctl stop mysql

Then uninstall the MySQL server package:

sudo apt remove mysql-server

This removes the server binaries.

If you want to keep things conservative, you can stop at that. If you were doing a full cleanup, you might also use purge and manually clean config/data, but since the goal here is to migrate and keep data available, the key step from the source is uninstalling the MySQL server itself.

Why this matters: MariaDB will replace MySQL as the database server. Removing MySQL first avoids conflicts between daemons and packages.

4. Add the MariaDB 10.5 Repository

Ubuntu 18.04’s default repo only has MariaDB 10.1, not 10.5.

So you need to add the official MariaDB 10.x repository before installing.

The source uses the repository generator on mariadb.org and selects a mirror, for example a DigitalOcean mirror, for MariaDB 10.5 on Ubuntu 18.04.

The general steps are:

  1. Go to the MariaDB repository generator on mariadb.org.
  2. Select:
  3. OS: Ubuntu
  4. Version: 18.04
  5. MariaDB version: 10.5
  6. A suitable mirror (e.g. DigitalOcean’s mirror as in the source).
  7. The site will generate repository configuration and commands you run on your server.

Follow the exact commands provided there on your Ubuntu 18.04 box.

Why this matters: without the MariaDB repo, apt will only see MariaDB 10.1, not the 10.5 you actually want.

5. Install MariaDB 10.5 Server

Once the repository is in place, install the MariaDB server package.

Run:

sudo apt update
sudo apt install mariadb-server

After installation, check the service status to make sure it’s running.

sudo systemctl status mariadb

You want to see something like active (running) in the output.

If it’s active-running, good—MariaDB is up.

Why this matters: we need a live MariaDB server to verify that your previous MySQL data is accessible and to test logins and queries.

6. Test MariaDB Login and Check Your Databases

Now, let’s make sure you can log in and that your databases are still there.

Log into MariaDB from the console:

mysql -u root -p

Enter the root password when prompted.

If login succeeds, list all databases:

SHOW DATABASES;

Here you check: do you see the same databases you had in MySQL (for example, wordpress)?

The source explicitly notes you should confirm that all databases that were in MySQL are also present in MariaDB and not deleted.

If they’re there, pick one database to inspect more closely.

For example, switch to the wordpress database:

USE wordpress;

Then list all tables in that database:

SHOW TABLES;

You should see the full list of WordPress tables.

Next, look at actual data from one of the tables.

For example, you can select rows from a table (in general form):

SELECT * FROM some_table_name LIMIT 10;

The important part is: confirm that table structure and data look correct.

Why this matters: this is your basic integrity check. If databases, tables, and data are visible and readable, your migration is effectively successful.

7. Confirm Migration Success and Next Steps

If:

  • MariaDB 10.5 is installed and mariadb service is active (running)
  • You can log in via mysql -u root -p
  • SHOW DATABASES; shows your old MySQL databases (e.g. wordpress)
  • USE your_db; and SHOW TABLES; work as expected
  • Simple SELECT queries show your real data

…then your migration from MySQL 5.7 to MariaDB 10.5 on Ubuntu 18.04 has been successfully completed.

At this point you can point your applications (WordPress, custom PHP apps, etc.) to the same socket/host and credentials you used for MySQL, since MariaDB exposes the same mysql client interface.

If something looks off:

  • You still have your mysqldump backups (like wordpress_backup.sql)
  • You can restore a database into MariaDB using standard import commands if needed

But as long as the databases appear unchanged and queries run normally, you’re good.

Need more help? Check the latest CrushEdge posts.

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.