How to Migrate a MySQL Database from One VPS to Another with Minimal Downtime

Moving a database to a new server sounds simple until you count what can go wrong: a dump that takes hours, a version mismatch that breaks the import, or a cutover that leaves your site writing to the old server while users read from the new one. The good news is that you can migrate MySQL database between VPS servers with only a few minutes of downtime, even for a database of several gigabytes, if you plan the move in two phases: copy the bulk of the data while the old server keeps running, then sync the last changes during a short maintenance window.

This guide covers the mysqldump method first, then shows how replication shrinks the window further for larger databases. Both use tools that ship with MySQL.

Before You Start: The Pre-Migration Checklist

Work through this list on both servers before you touch the data.

  • Match the MySQL versions. Check mysql --version on both VPS instances. Moving from MySQL 8.0 to 8.0 is safe; moving from 5.7 to 8.0 can break things, because 8.0 changed the default authentication plugin and removed some old features. If the versions differ, upgrade the old server first. Our guide on how to migrate a MySQL database to MariaDB on your VPS covers the extra steps that kind of switch needs.
  • Check disk space on the target. The dump file plus the imported database need roughly twice the current database size in free space. Confirm it with df -h, or the import will die halfway through.
  • Take a real backup first. A migration is not a backup. Make a separate copy of the database and store it somewhere other than either VPS, so a botched import never leaves you with nothing. If you want this handled for you, compare the options in our roundup of the best managed database backup services for VPS in 2026.
  • Note the users and grants. A mysqldump of one database does not carry MySQL user accounts. Dump the grants separately with mysqldump --system=users on MySQL 8, or record them by hand on older versions.
  • Check the character set and collation. Run SHOW CREATE DATABASE your_db; on the source and make sure the target uses the same defaults, or you may import text that comes back garbled.

Step by Step: Migrate MySQL Database Between VPS Instances

Use this method for databases up to a few gigabytes, where a full dump and import fits inside a maintenance window you can afford.

1. Dump the database on the old VPS

Log in to the old VPS and create a single-transaction dump. The --single-transaction flag keeps the dump consistent for InnoDB tables without locking them, so your site keeps serving reads while the dump runs:

mysqldump -u root -p --single-transaction --routines --triggers --events your_db > /tmp/your_db.sql

The --routines, --triggers, and --events flags matter. Leave them out and your stored procedures and scheduled events silently stay behind. For very large databases, pipe the dump through gzip to shrink the transfer: mysqldump ... | gzip > /tmp/your_db.sql.gz.

2. Copy the dump to the new VPS

Transfer the file with scp or rsync. Rsync is the better choice for large files because it resumes cleanly if the connection drops:

rsync -avz --progress /tmp/your_db.sql.gz root@new-vps:/tmp/

3. Create the database and import

On the new VPS, create an empty database with the same character set, then import the dump:

mysql -u root -p -e "CREATE DATABASE your_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
zcat /tmp/your_db.sql.gz | mysql -u root -p your_db

Watch the import for errors. A clean import ends with no output and a zero exit code. If you see errors about unknown collations or missing tables, stop and fix the cause first.

4. Recreate users and grants

Import the users dump you made earlier, or create the application user by hand and grant it the same privileges it had on the old server. Then run FLUSH PRIVILEGES;. Test the application credentials with a plain mysql -u app_user -p login from the new server before you switch anything.

Cut Over with Minimal Downtime

The dump-and-import method has one weak point: while the dump runs and the file transfers, new writes keep landing on the old server. Fix it with a short maintenance window: stop write traffic, redo the full dump (or dump just the changes since the first one), import it, point the application at the new server, and bring it back up. For a small database the window lasts a few minutes.

If your application is WordPress, the same cutover pattern applies to the whole site, not just the database. Our walkthrough of how to migrate a WordPress site to a new VPS with zero downtime shows how to move files and database together so the switch stays invisible to visitors.

Keep the old server running for at least 48 hours after the cutover. If something surfaces late, a bad index, a missing routine, a cron job still pointing at the old host, you can compare the two databases or roll back without a fresh migration.

Using Replication for Near-Zero Downtime

When the database is too large for a dump inside an acceptable window, a mysql replication migration is the better tool. Instead of copying a frozen snapshot, you set the new VPS up as a replica, let it catch up while the old server keeps serving traffic, then promote it to primary during a cutover that lasts seconds rather than hours.

The outline of the process:

  1. On the old server, enable binary logging and create a dedicated replication user.
  2. Take a consistent dump with --master-data=2 (or --source-data=2 on MySQL 8.0.23 and later) so the dump records the exact binary log position it came from.
  3. Import the dump on the new VPS and point replication at the old server with CHANGE REPLICATION SOURCE TO.
  4. Wait until SHOW REPLICA STATUS reports zero seconds behind the source.
  5. Stop writes on the old server, confirm the replica has caught up, promote the replica, and point the application at the new VPS.

Replication adds moving parts: binary log retention, network latency, and the risk that a long write stalls the replica. Test the full sequence on a staging copy first.

Verify the New Database Before You Switch Traffic

Check the new database before you switch traffic. Run these comparisons against both servers:

  • Row counts. SELECT COUNT(*) FROM on your largest tables, or use CHECKSUM TABLE for a stronger comparison.
  • Schema. Diff the output of SHOW CREATE TABLE for every table, or compare mysqldump --no-data output from both servers.
  • Routines and events. Check SHOW PROCEDURE STATUS, SHOW FUNCTION STATUS, and SHOW EVENTS on the new server.
  • Application smoke test. Point a staging copy of the application at the new database and test login, a write, and a search. A clean import can still fail the application if a grant or character set is wrong.

Common Mistakes That Break a MySQL Migration

A mysqldump migration fails in predictable ways. The most common is dumping without --single-transaction on a busy InnoDB database, which either locks tables and takes the site down during the dump or produces an inconsistent snapshot. Another is forgetting the routines, triggers, and events flags, which leaves the schema looking complete while scheduled jobs quietly stop running.

Version mismatches are the next trap. MySQL 8.0 defaults to caching_sha2_password, and an older client or application library may fail to authenticate against the new server even though the import itself succeeded. Check your application connector supports it before the move, or create the user with mysql_native_password as a deliberate, documented choice.

Finally, watch settings that do not travel in a dump: max_allowed_packet on the target must be at least as large as on the source, or imports of large rows fail, and time zone tables must exist on the target if your application uses named time zones. Both are quick to fix and easy to overlook during a cutover.

After the Move: Cleanup and Monitoring

Once traffic runs on the new VPS and the old server has sat idle for two days, shut down MySQL there instead of deleting anything. Keep the old dump and database for another week. Update cron jobs, backup scripts, and monitoring alerts to the new host, and confirm the next scheduled backup ran against it. A minimal downtime mysql migration only counts as finished when that first backup succeeds and the old server receives no traffic.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.