Five years ago, “schedule a four-hour Saturday window, run mysql_upgrade, pray” was an acceptable plan. Today it is not. A retail app loses money every hour the checkout is frozen; a B2B SaaS that pings its SLA over a “planned maintenance” string has just opened a contract conversation; a cron-driven analytics pipeline that misses one daily run for a vendor regulator triggers a 30-page report. The expectation now is that a MySQL major-version upgrade — 5.7 to 8.0, or 8.0 to 8.4 LTS — happens without the application going offline. This runbook is how Stack Harbor runs that upgrade in production.
What “zero-downtime” actually means in MySQL context
Strictly speaking, you cannot promote a different MySQL server from replica to primary in literal zero seconds. There is a moment where the old primary stops accepting writes, the new replica catches up, and the application’s connection pool re-targets the new write endpoint. The honest target is:
- Writes: 5 to 30 seconds of read-only, where the application sees
ER_OPTION_PREVENTS_STATEMENT (1290)for write statements but reads continue. - Reads: zero interruption. Read traffic stays on a replica throughout cutover.
- p95 latency: a single bump in the second the connection pool retargets, then back to baseline within 30 seconds.
- p99 latency: usually a two-to-five-second spike — this is the metric that catches connector layers that block on a stale connection until OS-level TCP timeout (default 75-120 seconds on many distros — see below).
Anything tighter than “5-30 seconds of read-only on writes” requires multi-primary topology (Group Replication, InnoDB Cluster, or external proxies that buffer writes), which has its own operational cost. For the 95% of workloads where 5-30 seconds of write-read-only is acceptable, the replica-seed strategy is what gets used.
Pre-upgrade audit
Two pre-checks are non-negotiable. They cover different ground and both must be clean.
# 1. MySQL Shell upgrade checker — most authoritative
mysqlsh -- util check-for-server-upgrade root@primary-5-7:3306 \
--target-version=8.0.36 \
--output-format=JSON > upgrade-check-5-7-to-8-0.json
# For 8.0 to 8.4 upgrades, target 8.4
mysqlsh -- util check-for-server-upgrade root@primary-8-0:3306 \
--target-version=8.4.0 \
--output-format=JSON > upgrade-check-8-0-to-8-4.json
# 2. Legacy mysqlcheck — catches table-level issues the shell may skip
mysqlcheck --all-databases --check-upgrade --user=root -p
ERROR items from the shell check are non-negotiable — they will break on the target version. WARNING items need triage, and three of them are almost always present in 5.7-vintage schemas:
- Reserved words used as identifiers.
rank,system,groups,lateral,over,row_numberwere added between 8.0 and 8.4. Every column, alias, and stored-routine variable using one needs backticks (`rank`) before cutover. - utf8mb3 tables. The old
utf8alias is being phased out in favor ofutf8mb4(real UTF-8, four-byte support). Convert before, not during, the upgrade. - Removed features in use. Query cache hints (
SQL_CACHE,SQL_NO_CACHE),mysql_native_passwordauthentication,--skip-host-cache, and the legacyOLD_PASSWORDfunction.
Then dump the server configuration that controls semantics and review it line by line:
SELECT @@sql_mode, @@character_set_server, @@collation_server,
@@default_authentication_plugin, @@innodb_default_row_format;
-- Per-user authentication plugin inventory
SELECT user, host, plugin FROM mysql.user ORDER BY plugin, user;
-- Per-table charset/collation inventory
SELECT table_schema, table_name, table_collation
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql','information_schema','performance_schema','sys')
ORDER BY table_collation, table_schema, table_name;
Inventory the replication topology — number of replicas, baseline Seconds_Behind_Source under peak load, whether GTID is enabled. Without GTID, the cutover is materially harder because the binary-log position handoff has to be exact. If you find GTID disabled in 2026, the first step is enabling it on the 5.7 source (a non-disruptive online operation) and letting it stabilize for a week before the upgrade.
Inventory application connector versions. The single most common cutover failure is an old PHP, Python, or Node connector that does not speak caching_sha2_password (the new 8.0 default) and fails to authenticate the moment the application points at the new primary. Test connectivity from every application class — including cron runners, queue workers, analytics jobs, and admin tools — against an 8.0 staging instance before the cutover is scheduled.
The replica-seed strategy
The pattern is straightforward: build a fresh replica on the target version, replicate from the old primary into it, validate against real traffic, then flip the writer. Asymmetric major-version replication (older primary → newer replica) is supported one step at a time across adjacent majors (5.7 → 8.0, 8.0 → 8.4). It is not supported the other way around; once the new node is the writer, you cannot replicate from 8.0 back to 5.7 except via logical dump-and-restore.
Step-by-step runbook
1. Take a hot snapshot of the source primary
Two snapshot mechanisms work in production: Percona XtraBackup (or MySQL Enterprise Backup) and the MySQL Shell clone plugin. XtraBackup is the durable choice for any version from 5.7 forward; the clone plugin is 8.0-only but is a single command from a mysqlsh prompt.
# XtraBackup on a 5.7 source — stream straight into the target machine
xtrabackup --backup --stream=xbstream --user=backup --password=... \
--target-dir=/tmp/xb \
| ssh new-replica "xbstream -x -C /var/lib/mysql/"
# On the new replica
xtrabackup --prepare --target-dir=/var/lib/mysql/
chown -R mysql:mysql /var/lib/mysql/
Record the binlog file and position at the moment of the snapshot — XtraBackup writes them to xtrabackup_binlog_info. With GTID enabled, the executed-GTID set in xtrabackup_binlog_info is what CHANGE REPLICATION SOURCE TO ... FOR CHANNEL '' will use.
2. Build the new replica on the target MySQL version
Install the target version cleanly. Do not attempt an in-place binary upgrade on the snapshot — the data dictionary upgrade runs during the first start of the target version against the restored data directory.
# Install MySQL 8.0 (or 8.4) using the distro's official repo
apt install mysql-server=8.0.36-* mysql-client=8.0.36-*
# First start performs the data-dictionary upgrade automatically (5.7 to 8.0)
systemctl start mysql
# Watch the error log — every prior-version table is reported
journalctl -u mysql -f
The first start can take 5-30 minutes on a large schema as the data dictionary is rebuilt. This is normal. The replica is not yet replicating during this phase.
3. Start replication from the old primary
Once the new replica is up on the target version, point it at the old primary:
-- On the new replica (MySQL 8.0/8.4)
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='primary-5-7.internal',
SOURCE_USER='repl',
SOURCE_PASSWORD='...',
SOURCE_AUTO_POSITION=1, -- requires GTID; non-GTID uses file+pos
SOURCE_SSL=1,
SOURCE_SSL_VERIFY_SERVER_CERT=1;
START REPLICA;
SHOW REPLICA STATUS\G
-- Replica_IO_Running: Yes
-- Replica_SQL_Running: Yes
-- Seconds_Behind_Source: 0 (after initial catch-up)
If the schema contains tables that use removed types or syntax (the upgrade check should have caught these), replication will fail with a clear SQL error here. Fix on the 5.7 source, then START REPLICA again. Replication runs forward from 5.7 to 8.0 cleanly; the limits are removed-syntax DDL events from the source and any application-level use of removed features in stored routines.
4. Run replication through at least one full daily peak
A replica that catches up overnight tells you nothing about how it behaves at 2pm on a Wednesday when the application is hammering it. Run replication continuously for at least 24 hours covering one full peak. Monitor:
Seconds_Behind_Source— should not climb above the source’s write workload latency. If it does, the new version’s optimizer is doing something different on a hot query — investigate before cutover.Last_SQL_Error/Last_IO_Error— any non-empty value blocks cutover.- Replica resource metrics — InnoDB buffer pool, disk I/O, CPU. The new version may have different memory accounting;
innodb_buffer_pool_sizeset the same as on 5.7 may behave differently in 8.0+.
5. Validate the application against the new replica’s reads
ProxySQL (or HAProxy with read/write split) makes this clean: add the new replica to the read hostgroup at low weight first, then ramp up. The application sees identical schema, identical data, but its reads are now being served by 8.0/8.4.
-- ProxySQL admin
INSERT INTO mysql_servers (hostgroup_id, hostname, port, weight, status)
VALUES (20, 'new-replica-8-0.internal', 3306, 10, 'ONLINE');
LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;
-- Ramp the weight up as confidence grows
UPDATE mysql_servers SET weight=100
WHERE hostname='new-replica-8-0.internal';
LOAD MYSQL SERVERS TO RUNTIME;
Watch the application’s slow query log and error log for queries that ran on 5.7 but error on 8.0 — most commonly GROUP BY queries that worked under permissive sql_mode but fail ONLY_FULL_GROUP_BY. Fix on the application side, deploy, then proceed.
6. Schedule the cutover window
Even a 5-to-30-second read-only window is communicated. The window is 15 minutes (the cutover itself is seconds; the buffer is for the unexpected). Pick a known low-traffic interval — for most North American B2B apps this is 03:00 Eastern; for retail, it’s 02:00-04:00 local. Document the exact ProxySQL admin commands in a checklist, dry-run them against a staging copy, and have a rollback runner ready in a second terminal before T-0.
7. The cutover sequence
-- T-0 (on the old primary)
SET GLOBAL read_only = ON;
SET GLOBAL super_read_only = ON; -- 8.0+ syntax; on 5.7 omit
Application writes immediately fail with error 1290 (ER_OPTION_PREVENTS_STATEMENT). The application should retry these on the next request — this is what makes the read-only window survivable. Connection pools that buffer writes for retry (most modern ORMs do) experience a sub-second pause rather than an error to the user.
-- T+1 to T+10 (on the new replica)
-- Wait for the replica to catch up — usually under 5 seconds
SHOW REPLICA STATUS\G
-- Seconds_Behind_Source: 0
-- Replica_IO_State: Waiting for source to send event
-- Replica_SQL_Running_State: Replica has read all relay log
-- Once at 0, stop and reset replication
STOP REPLICA;
RESET REPLICA ALL;
-- The new primary is now a standalone writable server
SET GLOBAL read_only = OFF;
SET GLOBAL super_read_only = OFF;
-- T+10 to T+20 (on ProxySQL)
-- Flip the writer hostgroup
UPDATE mysql_servers SET hostgroup_id=10
WHERE hostname='new-replica-8-0.internal';
UPDATE mysql_servers SET hostgroup_id=30, status='OFFLINE_SOFT'
WHERE hostname='primary-5-7.internal';
LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;
Application writes resume against the new primary. Connection pools that hold a connection to the old primary see an OFFLINE_SOFT drain — ProxySQL stops sending new queries to it but lets existing queries finish, which is what you want.
8. Reverse replication for rollback
-- On the old primary (5.7) — now a replica of the new primary
SET GLOBAL read_only = ON;
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='new-primary-8-0.internal',
SOURCE_USER='repl',
SOURCE_PASSWORD='...',
SOURCE_AUTO_POSITION=1;
START REPLICA;
Wait. 5.7 cannot replicate from 8.0 in many configurations — the binary-log format from 8.0 may include events 5.7 does not understand (e.g., events involving caching_sha2_password user changes). Test this in your staging environment first. If 5.7-as-replica-of-8.0 fails, the rollback path is logical-replay only: dump the binary log from the new primary covering the post-cutover window, then replay against the old primary if rollback is invoked. Document which path applies to your setup.
9. Post-cutover validation
- Synthetic write probes from each application class — confirm every cron, queue worker, and admin tool can authenticate and write to the new primary.
- Connection-error metrics from the application — chase any spike in
MySQL server has gone awayorLost connection to MySQL server during queryto its source within the first hour. - Read replica lag from any additional replicas attached to the new primary.
- Slow query log on the new primary — any query that was sub-100ms on 5.7 and is now over 500ms on 8.0/8.4 needs an immediate explain plan; this is the optimizer change tax that the validation phase should have caught but occasionally surfaces under cutover-time traffic mix.
Rollback plan
Keep the old primary intact and read-only for 48 hours minimum after cutover. The rollback trigger is a hard application failure that the team’s incident response has determined will not resolve within the published recovery target. Trivial issues — a slow query that needs an index, a single broken cron — are fixed forward, not rolled back.
If rollback is triggered:
- Application enters read-only mode against the new primary.
- Capture the binary log range from the new primary covering the post-cutover window.
- Decide: replay onto the old primary (if 5.7 can consume the 8.0 log), or accept a small data loss window equal to the post-cutover write volume that did not yet replicate back.
- Set
read_only = OFFon the old primary. - ProxySQL writer hostgroup flipped back.
- Application resumes against the old primary.
After 48 hours, if no rollback is in flight and the application metrics are stable, dismantle the old-primary-as-replica role and either retire the host or repurpose it as a new replica of the new primary (after an in-place upgrade or a fresh build, depending on the version gap).
Things that go wrong
Authentication plugin mismatch. 8.0’s default is caching_sha2_password; older application connectors (PHP mysqlnd before PHP 7.4, Python mysqlclient before 2.0, Node mysql v2 — but not mysql2) cannot authenticate. The fix on the new primary, before cutover, is to create a transition user with mysql_native_password until every connector is upgraded:
CREATE USER 'app'@'%' IDENTIFIED WITH mysql_native_password BY '...';
GRANT ... ON ...* TO 'app'@'%';
Note: mysql_native_password is removed in 8.4. The transition plugin works for 8.0 only. If you are going straight from 5.7 to 8.4, every connector must support caching_sha2_password before cutover — there is no transition fallback.
sql_mode tightening. Both 8.0 and 8.4 ship more restrictive defaults. NO_ZERO_DATE, NO_ZERO_IN_DATE, STRICT_TRANS_TABLES, and ONLY_FULL_GROUP_BY will reject statements that worked silently on 5.7. The fix is to make the application correct on sql_mode='TRADITIONAL' before cutover, not to relax sql_mode on the new primary — that just postpones the work and adds a debt line item.
utf8mb3 to utf8mb4 default. The server-wide default character set changed to utf8mb4 in 8.0. Tables created without an explicit charset now use utf8mb4 by default. Tables created on 5.7 retain their utf8mb3 collation unless converted. This usually does not break anything until a JOIN between a 5.7-vintage table and a freshly-created one hits a collation-mismatch error. Convert pre-existing tables explicitly before cutover.
Removed features. The query cache (query_cache_type, query_cache_size, SQL_CACHE hint) was removed in 8.0 — any my.cnf reference to it will fail server startup. mysql_native_password is removed in 8.4. --skip-host-cache is removed in 8.4. Audit my.cnf line by line on the new version’s defaults.
Replication GTID compatibility. GTIDs are forward-compatible 5.7 to 8.0. They are forward-compatible 8.0 to 8.4. They are not reverse-compatible. Once the new primary is writing GTIDs in 8.4 format, the old primary cannot consume them. This shapes the rollback strategy.
InnoDB redo log behavior. 8.0.30 changed innodb_redo_log_capacity (single tunable) vs the old 5.7 innodb_log_file_size × innodb_log_files_in_group pair. Set innodb_redo_log_capacity explicitly on the new primary; leaving the old pair in my.cnf is ignored and you fall to the default, which may be smaller than what your workload sized for.
OS-level connection timeouts. Application connectors that hold a TCP connection to the old primary at cutover see the connection break only when the OS-level tcp_keepalive window expires. On Linux that defaults to 7,200 seconds (two hours). For long-lived persistent connections — daemons, queue workers — set the connector’s idle-timeout to under 5 minutes, or set tcp_keepalive_time lower on the application host. Otherwise the connection pool happily hands out dead connections for hours after cutover.
Variations
MariaDB to MySQL (or the reverse). Replication between the two ecosystems is no longer supported in any forward-compatible way once MariaDB has diverged past 10.5. The replica-seed strategy does not apply. The path is: logical dump (mydumper for parallel dump, or mysqldump --single-transaction), restore against the target, then any pending writes replayed from binary log if possible, or accepted as a maintenance-window write gap if not. Plan for hours, not seconds, of write downtime.
On AWS RDS or Aurora. AWS RDS Blue/Green Deployments automate exactly this pattern — RDS builds the green environment on the target version, replicates from blue, validates, and switches over with a typical 1-minute write interruption. The constraints documented above (authentication plugin, sql_mode, charset) apply identically; the orchestration is what AWS provides. For Aurora, the equivalent is db.cluster.upgrade against an Aurora MySQL major version with a writer endpoint switch.
On Google Cloud SQL. The Cloud SQL major-version upgrade in-place is offered, but the supported zero-downtime path is identical to this runbook: create a new instance on the target version, set up read replication, validate, fail over by changing the endpoint that the application uses. Cloud SQL does not yet have an RDS-style blue/green abstraction; the customer manages the cutover.
On bare metal or self-managed cloud VMs. This runbook applies as-is. The only addition is HAProxy or ProxySQL as the routing layer; without one, the cutover is a DNS or VIP move and the application reconnection time is bounded by DNS TTL — set the TTL to 30 seconds well before cutover, and document the rollback DNS change in the same checklist.
When Stack Harbor runs this for you
A MySQL major-version upgrade is a once-per-multi-year event for most teams. Running the dry-run, the catch-up monitoring, the cutover at 3am, and the 48-hour rollback watch is not a skill that pays off to keep in-house unless your application is itself a database product. We run this end to end as part of Migration Services — the audit, the staging replication, the cutover window, the rollback contingency, and the 24-hour post-cutover watch. Day two onward, the upgraded cluster sits under Managed Operations with the routine mysql_upgrade, security patching, and minor-version rollouts handled on cadence. The compute itself runs on Cloud Compute when you want us holding the floor; we attach to your own AWS or GCP account when you don’t.