Which tool for which move
Four kinds of tools cover almost every MySQL and MariaDB move: a logical dump and load (mysqldump, mariadb-dump, MySQL Shell, mydumper), an in-place upgrade of the server, binary log replication into a new server, and the managed upgrade or blue/green features of the cloud providers. The table compares them; the downtime classes are those of the guide on migration downtime.
| Tool or route | Typical use | Downtime | Way back | Prerequisites |
|---|---|---|---|---|
mysqldump / mariadb-dump | Small and medium databases, any move between MySQL and MariaDB versions, MariaDB to MySQL | Offline (hours): writes stop from the start of the dump until the switch | Old server unchanged | InnoDB for a consistent dump without locks; DEFINER accounts or privileges on the target |
| MySQL Shell dump and load | MySQL source of any size, to a new server or a managed service | Offline, but much shorter thanks to parallel threads | Old server unchanged | MySQL 5.7 or later as source (not MariaDB); local_infile on the target during the load |
| mydumper / myloader | Large MySQL or MariaDB databases, parallel dump and load | Offline, shorter than a single-threaded dump | Old server unchanged | Separate open-source tool; --routines, --triggers, --events must be asked for |
| In-place upgrade | Own server or VM, next LTS series | Offline (minutes to an hour, plus testing) | Restore of the backup taken just before: no downgrade | Upgrade checker clean; one LTS series per step |
| Managed major version upgrade | Upgrade within RDS, Azure Flexible Server or Cloud SQL | Offline (minutes to an hour) | Restore of the snapshot taken before | Checker or precheck clean; one major version per step |
| Binary log replication | New server or managed service, MySQL to MySQL or MariaDB to MariaDB | Near-zero (seconds to minutes) | Old server stays current until the switch; afterwards only with reverse replication | log_bin, binlog_format = ROW, unique server_id, primary keys, enough binlog retention |
| RDS / Aurora blue/green | Upgrade or parameter change within RDS for MySQL, RDS for MariaDB or Aurora MySQL | Near-zero (typically under a minute) | Old (blue) instance kept, but no longer receiving writes | Binary logging on the blue instance; event_scheduler off on green at creation |
| Azure DMS or Google DMS (online) | Move into Azure Flexible Server or Cloud SQL | Minimal (minutes) | Source unchanged until the cutover | Binlog in ROW format, retention, primary keys |
- Upgrade on your own server (5.7 → 8.0 → 8.4 → 9.7): an in-place upgrade per LTS series, or a new server with the new version that you fill with a dump and load or keep in sync with replication. The new server keeps the old one as the way back.
- Move to RDS, Aurora, Azure Flexible Server or Cloud SQL: MySQL Shell dump and load from a MySQL source,
mysqldumpfor small databases, and replication or the provider's migration service when the switch has to be short. - Upgrade within RDS or Aurora: a blue/green deployment, or the in-place major version upgrade of the service in a maintenance window.
- MariaDB to MySQL: only a dump with
mariadb-dump, with a few corrections, loaded with themysqlclient. There is no in-place upgrade or replication path from MariaDB into MySQL 8.0 or later. - Size: up to a few tens of gigabytes a single-threaded dump usually fits in a night; above that, the parallel tools (MySQL Shell, mydumper) or replication are worth the extra setup.
Whatever the tool, rehearse the complete run on a copy and write down how long each step takes: that is your real downtime. The free scan reads the structure of your database and flags what stops these tools: non-InnoDB tables, zero dates, utf8mb3 columns, DEFINER objects, events and, where the script can read them, accounts with mysql_native_password.
mysqldump and mariadb-dump
mysqldump writes the database as SQL statements: CREATE TABLE, INSERT and the code objects. mariadb-dump is the same tool in MariaDB; the old name mysqldump still exists there as a symbolic link, deprecated since MariaDB 11.0. It is single-threaded and always available, which makes it the default for small and medium databases and the only route from MariaDB to MySQL.
Prerequisites: an account with SELECT, SHOW VIEW, TRIGGER and EVENT on the database and read access to the routine definitions (LOCK TABLES only without --single-transaction), enough disk space for the dump file, and on the target the same lower_case_table_names, character set, collation and time zone as on the source. Run the check below on the source first.
- 1. Prepare the target. On your own server, set the values in
my.cnf; on a managed service, create a parameter group (RDS, Aurora), set the server parameters (Azure) or the flags (Cloud SQL) before the load.lower_case_table_namescan only be set when the server or instance is created. - 2. Dump with the right options.
--single-transactiontakes one consistent snapshot of the InnoDB tables without locking them (MyISAM and other engines are not consistent);--quickstreams large tables row by row;--routinesand--eventsadd stored procedures, functions and events, which are not dumped by default (triggers are);--hex-blobwrites binary columns as hexadecimal so that no character conversion can touch them;--default-character-set=utf8mb4avoids conversion of 4-byte characters;--no-tablespacesleaves out tablespace statements, which otherwise need thePROCESSprivilege and fail on managed services. - 3. Create the database and load the dump with the
mysqlclient and the same character set. - 4. Recreate the accounts and refresh the statistics. A dump of one database does not contain accounts; create them on the target with
caching_sha2_password(MySQL 8.0 and later) and their grants, then runANALYZE TABLE.
-- On the source: what the dump will carry, and what can stop the load
SELECT table_name, engine FROM information_schema.tables
WHERE table_schema = 'shop' AND table_type = 'BASE TABLE' AND engine <> 'InnoDB';
SELECT 'routine' AS kind, definer FROM information_schema.routines WHERE routine_schema = 'shop'
UNION SELECT 'view', definer FROM information_schema.views WHERE table_schema = 'shop'
UNION SELECT 'trigger', definer FROM information_schema.triggers WHERE trigger_schema = 'shop'
UNION SELECT 'event', definer FROM information_schema.events WHERE event_schema = 'shop';
SELECT @@lower_case_table_names, @@global.time_zone, @@system_time_zone, @@max_allowed_packet,
@@character_set_server, @@collation_server, @@event_scheduler, @@global.sql_mode;# Parameter group (RDS, Aurora), server parameters (Azure) or flags (Cloud SQL), set before the load.
# Names differ slightly per service (Cloud SQL: default_time_zone).
character_set_server = utf8mb4 # as on the source
collation_server = utf8mb4_0900_ai_ci # as on the source
max_allowed_packet = 1073741824 # rows with large text or blob values
time_zone = <source time zone> # SELECT @@global.time_zone, @@system_time_zone;
lower_case_table_names = <source value> # only when the instance is created: cannot be changed later
log_bin_trust_function_creators = 1 # the dump contains functions and binary logging is on
event_scheduler = ON # the database has events
local_infile = 1 # only for MySQL Shell util.loadDump, back to 0 afterwards# 1. Dump the source: one consistent snapshot of the InnoDB tables, without locks
mysqldump -h <source-host> -u <user> -p --single-transaction --quick --routines --triggers --events --hex-blob \
--default-character-set=utf8mb4 --no-tablespaces shop > /backup/shop.sql
# MariaDB source: the same options with mariadb-dump
# 2. Create the database on the target, with the character set and collation of the source
mysql -h <target-endpoint> -u <admin> -p -e 'CREATE DATABASE IF NOT EXISTS `shop` CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;'
# 3. Load the dump
mysql -h <target-endpoint> -u <admin> -p --default-character-set=utf8mb4 shop < /backup/shop.sql-- 4. On the target: the application accounts (a database dump does not contain them), then fresh statistics
CREATE USER 'app'@'%' IDENTIFIED WITH caching_sha2_password BY '<new password>';
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `shop`.* TO 'app'@'%';
ANALYZE TABLE `shop`.`customers`, `shop`.`orders`;# Option A: create the DEFINER accounts on the target before the load (keeps SQL SECURITY DEFINER as it is)
# Option B: remove the DEFINER clauses, so that the objects belong to the account that loads the dump
sed -E -i 's/DEFINER=`[^`]+`@`[^`]+`//g' /backup/shop.sql # GNU sed; on macOS: sed -E -i '' …
grep -c 'DEFINER=' /backup/shop.sql # should print 0DEFINER on managed services. Every view, routine, trigger and event has a DEFINER account. Creating an object for another account needs SUPER, SET_USER_ID (MySQL 8.0) or SET_ANY_DEFINER (MySQL 8.4 and later), which the admin user of RDS, Aurora, Azure or Cloud SQL does not have: the load then stops with ERROR 1227. Either create the same accounts on the target first and load as an account that may use them, or remove the DEFINER clauses so that the objects belong to the loading account. Removing them changes who the objects run as when they use SQL SECURITY DEFINER; test the application afterwards. With binary logging on, which is the case on managed services with backups, creating functions also needs log_bin_trust_function_creators = 1, otherwise the load stops with ERROR 1418.
Timing and downtime. The dump reads every row and the load rebuilds every index, so the load usually takes several times as long as the dump. Measure both on a copy. Writes that reach the source after the start of the dump are not in it: for an offline move, stop the application before the dump and keep it stopped until the switch.
Limits. One thread for the dump and one for the load; non-InnoDB tables are only consistent when nothing writes to them; accounts, server settings and the time zone tables are not part of a database dump. Do not dump the mysql system database to load it into another version: recreate accounts with CREATE USER and GRANT, or use MySQL Shell's dumpInstance with loadUsers.
Verification. The mysql client stops at the first error and shows the line number: a load that ends without output has run completely. Then compare row counts and objects as described under verification below.
MySQL Shell: util.dumpInstance, util.dumpSchemas and util.loadDump
MySQL Shell (mysqlsh) has dump and load utilities that work in parallel: util.dumpInstance dumps the whole server including accounts, util.dumpSchemas one or more databases, and util.loadDump loads either into a MySQL server. The data is split into chunks, compressed and loaded by several threads at once, and an interrupted load resumes from its progress file. For a MySQL source of more than a few gigabytes it is usually the fastest logical route.
Prerequisites: a MySQL source of version 5.7 or later (MySQL Shell does not support MariaDB as a source), a recent MySQL Shell (at least as new as the target version) on a machine with enough disk space and network bandwidth to both servers, and local_infile switched on at the target during the load, because util.loadDump loads the data with LOAD DATA LOCAL INFILE. The account that dumps needs BACKUP_ADMIN and RELOAD for a fully consistent dump with consistent: true; without them MySQL Shell falls back to table locks and an extra consistency check.
- 1. Run the upgrade checker on the source with the target version, also for a move between servers:
util.checkForServerUpgradelists reserved words, removed SQL modes, obsolete data types, authentication plugins and other blockers. Fix every error before the dump. - 2. Dump with
threadsset to the number of cores you can spare on the source (default 4) andconsistent: true(the default). For a managed target addcompatibilityoptions:strip_definersremoves DEFINER clauses and setsSQL SECURITY INVOKER,strip_restricted_grantsremoves privileges the service does not allow. Other options arestrip_tablespaces,force_innodb,skip_invalid_accountsandcreate_invisible_pks. - 3. Prepare the target: the same parameters as for
mysqldump, pluslocal_infile = 1for the duration of the load. - 4. Load with
util.loadDump: first withdryRun: true, which shows what would be done and the errors it already sees, then for real.loadUsersis off by default; switch it on only for adumpInstancedump whose accounts you want to carry over.deferTableIndexes(default: full-text indexes only) can build all secondary indexes after the data with the valueall. - 5. Switch
local_infileoff again, recreate the accounts if you did not load them, and runANALYZE TABLE.
# 1. On the source: the upgrade checker for the target version (MySQL Shell at least as new as the target)
mysqlsh <admin>@<source-host> --js -e "util.checkForServerUpgrade({targetVersion: '9.7.0'})"
# 2. Dump: parallel, compressed, consistent for InnoDB tables
mysqlsh <user>@<source-host> --js -e "util.dumpSchemas(['shop'], '/backup/shop', {threads: 4, consistent: true})"
# to a managed service (RDS, Aurora, Azure, Cloud SQL): with compatibility options
mysqlsh <user>@<source-host> --js -e "util.dumpSchemas(['shop'], '/backup/shop', {threads: 4, compatibility: ['strip_definers', 'strip_restricted_grants'], consistent: true})"
# 3. Target: LOAD DATA LOCAL INFILE must be allowed for the duration of the load
mysql -h <target-endpoint> -u <admin> -p -e 'SET GLOBAL local_infile = ON;' # managed service: local_infile = 1 in the parameters
# 4. Dry run, then the load (an interrupted load resumes from its progress file when started again)
mysqlsh <admin>@<target-endpoint> --js -e "util.loadDump('/backup/shop', {threads: 4, dryRun: true})"
mysqlsh <admin>@<target-endpoint> --js -e "util.loadDump('/backup/shop', {threads: 4})"
# 5. Switch local_infile off again
mysql -h <target-endpoint> -u <admin> -p -e 'SET GLOBAL local_infile = OFF;'Versions. util.loadDump accepts dumps from the same or the previous major version. A dump from an older, non-consecutive version is refused unless you set ignoreVersion: true, and even then it only works if the schema has no incompatibilities; Oracle's upgrade paths do not allow skipping an LTS series, so 5.7 to 8.4 goes through 8.0 there as well. The checker's targetVersion can be any release up to the version of the MySQL Shell you run, so use a MySQL Shell at least as new as the target.
Timing. Dump and load scale with the number of threads until the disks or the network are the limit; on a server with several cores it is often several times faster than mysqldump. Downtime is still offline: writes after the start of the dump are not in it.
Limits. No MariaDB source; consistency only for InnoDB tables; strip_definers changes the security context of views and routines; the dump format is MySQL Shell's own, so the load also needs MySQL Shell.
Verification. MySQL Shell reports the number of rows and warnings at the end of the load; compare row counts and objects as below.
mydumper and myloader
mydumper and myloader are an open-source pair, independent of Oracle and MariaDB, that dumps and loads in parallel. They work with MySQL, MariaDB and Percona Server, which makes them the parallel option for large MariaDB databases. mydumper takes a consistent snapshot of the InnoDB tables and writes one or more files per table, plus a metadata file with the binary log position of the snapshot, which you can use to start replication afterwards.
# Dump: 4 threads, compressed; routines, triggers and events only when asked for
mydumper --host <source-host> --user <user> --ask-password --database shop --outputdir /backup/shop-mydumper \
--threads 4 --compress --routines --triggers --events
# the metadata file in the output directory records the binary log position (and GTID set) of the snapshot
# Load
myloader --host <target-endpoint> --user <admin> --ask-password --database shop --directory /backup/shop-mydumper --threads 4Routines, triggers and events are only dumped with --routines, --triggers and --events. Option names change between releases (for example the overwrite option of myloader, now --drop-table): check --help of the version you install. The same DEFINER, character set and MariaDB-to-MySQL corrections apply as for mysqldump; for a MariaDB-to-MySQL move, mariadb-dump with the corrections below is the tested route.
In-place upgrades: one LTS series at a time
MySQL upgrades in place only to the next LTS series: 5.7 → 8.0 → 8.4 → 9.7. Skipping a series is not supported, and Oracle's upgrade paths apply the same rule to logical dumps and replication. A MySQL server cannot be downgraded in place, so the way back is a restore of the backup taken just before. From MySQL 8.0.16 the server upgrades the data dictionary and system tables itself at the first start; mysql_upgrade is no longer used.
Run the upgrade checker of MySQL Shell before every step, with the target version of that step, and fix everything it reports as an error. On managed services the provider runs a similar check before the upgrade (Azure: Validate; Cloud SQL: a precheck that runs the MySQL Shell checker).
- Authentication: MySQL 8.0 makes
caching_sha2_passwordthe default, 8.4 no longer loadsmysql_native_passwordby default, and 9.0 removed it. Accounts that still use it cannot log in after an upgrade to 9.x: switch them before the upgrade and check that every client connector supportscaching_sha2_password(TLS or RSA key exchange). - Reserved words: new reserved words in 8.0 (for example
RANK,GROUPS,WINDOW,LEAD,LAG,SYSTEM), 8.4 (QUALIFY,TABLESAMPLE) and 9.x (EXTERNAL,LIBRARY) break unquoted table and column names in views, routines and application SQL. - utf8mb3:
utf8is an alias of the deprecatedutf8mb3, which stores no 4-byte characters such as emoji. Converting toutf8mb4changes index length limits and can change sort order and uniqueness with the new collation. - Zero dates and SQL modes:
NO_AUTO_CREATE_USERno longer exists in 8.0 and stops the server or the load when it is insql_modeor in routines; strict modes refuse'0000-00-00'defaults (ERROR 1067). - Replication statements: 8.4 removed
CHANGE MASTER TO,START SLAVE,SHOW SLAVE STATUSandSHOW MASTER STATUS; scripts and monitoring must use theSOURCEandREPLICAforms andSHOW BINARY LOG STATUS. - Spatial indexes and table functions: MySQL 8.0.41, 8.4.4 and 9.2.0 fixed a bug that could corrupt spatial indexes; drop them before the upgrade and recreate them afterwards. From 9.3 the upgrade opens every table whose constraints, defaults, partitioning or virtual columns use SQL functions and stops when one cannot be opened.
# Before every step: a full backup, and the upgrade checker for the next LTS series
mysqlsh <admin>@<host> --js -e "util.checkForServerUpgrade({targetVersion: '8.4.0'})"
# Accounts that still use mysql_native_password (disabled by default in 8.4, removed in 9.0)
mysql -u root -p -e "SELECT user, host, plugin FROM mysql.user WHERE plugin = 'mysql_native_password';"
# per account, with its password: ALTER USER 'app'@'%' IDENTIFIED WITH caching_sha2_password BY '<password>';
# In-place upgrade of one server: slow shutdown, new binaries, start
mysql -u root -p -e 'SET GLOBAL innodb_fast_shutdown = 0;'
mysqladmin -u root -p shutdown
# install the binaries of the next LTS series (package manager or tarball); check my.cnf for removed options
sudo systemctl start mysqld
# the data dictionary and system tables are upgraded at the first start (MySQL 8.0.16 and later):
# read the error log for upgrade errors before the application connects# Amazon RDS for MySQL: snapshot first, then one major version at a time
aws rds create-db-snapshot --db-instance-identifier <id> --db-snapshot-identifier <id>-before-upgrade
aws rds modify-db-instance --db-instance-identifier <id> --engine-version <version> \
--db-parameter-group-name <parameter group for the new version> --allow-major-version-upgrade --apply-immediately
# Azure Database for MySQL Flexible Server (take an on-demand backup first)
az mysql flexible-server upgrade --resource-group <resource group> --name <server> --version 8.4
# Google Cloud SQL for MySQL (precheck, then the upgrade; Cloud SQL takes upgrade backups itself)
gcloud beta sql instances pre-check-major-version-upgrade <instance> --target-database-version=MYSQL_8_4
gcloud sql instances patch <instance> --database-version=MYSQL_8_4Timing. The upgrade itself usually takes minutes; a slow shutdown (innodb_fast_shutdown = 0) and many tables make it longer. Plan the window for the backup, the upgrade, the checks and, if needed, a restore.
Managed services. RDS, Azure Flexible Server and Cloud SQL upgrade one major version at a time as well. Cloud SQL supports 5.7 → 8.0, 8.0 → 8.4 and 8.4 → 9.7 in place and takes upgrade backups itself; Azure supports 5.7 → 8.0 and 8.0 → 8.4 and asks you to upgrade read replicas first. A failed upgrade is rolled back by the service, but a successful one cannot be undone: the way back is a restore to a new instance.
Verification. Read the error log after the first start, check SELECT VERSION(); and the state of the replicas, and test the application, especially logins and queries with the new reserved words.
MariaDB to MySQL, and MySQL to MariaDB
MariaDB started as a fork of MySQL 5.1/5.5 and has developed separately since: other system tables, authentication plugins, GTID format, collations and features. A move from MariaDB to MySQL is therefore a product switch, not an upgrade. There is no in-place route and no binary log replication from MariaDB into MySQL 8.0 or later, and MySQL Shell's dump utilities do not read MariaDB. The route is a dump with mariadb-dump (or mydumper), corrected and loaded with the mysql client, and tested on MySQL.
The corrections below are the ones the paid report's runbook uses; they were run for real from MariaDB 10.11 into MySQL 9.7.
- The sandbox line: MariaDB 10.5.25, 10.6.18, 10.11.8, 11.x and later write
/*M!999999\- enable the sandbox mode */as the first line of the dump. Older MariaDB clients refuse it (Unknown command '\-'); the MySQL clients skip it. Removing the line is harmless. - NO_AUTO_CREATE_USER: routines and triggers in the dump carry the
sql_modethey were created with, often includingNO_AUTO_CREATE_USER, which MySQL 8.0 and later refuse withERROR 1231. Remove it from the dump. - Generated columns:
mariadb-dumpwrites the values of generated columns in theINSERTstatements, and MySQL refuses them withERROR 3105. Dump the data of those tables separately, load it into a staging table and copy only the stored columns; load the triggers last so that they do not fire during that copy. - Collations: MariaDB 11's
uca1400collations (for exampleutf8mb4_uca1400_ai_ci) and the_nopad_collations do not exist in MySQL (ERROR 1273). Convert those tables on a copy of the source to a collation MySQL knows, such asutf8mb4_unicode_ci, or replace the name in the dump and test sort order and uniqueness on MySQL'sutf8mb4_0900_ai_ci. - JSON: in MariaDB
JSONis an alias ofLONGTEXTwith aJSON_VALIDcheck, so the dump createsLONGTEXTcolumns. They load as text; convert them to MySQL's binaryJSONtype afterwards where the application uses JSON functions, and test those queries. - MariaDB-only features: sequences, system-versioned tables, Oracle-mode packages and invisible columns cannot be created on MySQL and have to be rewritten before the move. The
grepin step 2 finds them. - Accounts: MariaDB password hashes and plugins cannot be reused on MySQL 9. Create each account anew with
caching_sha2_passwordand a password, and copy the grants fromSHOW GRANTS.
# 1. Dump. Tables with generated columns (here: orders) get their data in a separate file,
# and the triggers come last so that they do not fire while that data is loaded
mariadb-dump -h <source-host> -u <user> -p --single-transaction --quick --routines --skip-triggers --events --hex-blob \
--default-character-set=utf8mb4 --no-tablespaces --ignore-table-data='shop.orders' shop > /backup/shop.sql
mariadb-dump -h <source-host> -u <user> -p --single-transaction --quick --no-create-info --complete-insert --skip-add-locks --skip-disable-keys --skip-triggers --hex-blob \
--default-character-set=utf8mb4 shop 'orders' > /backup/shop-generated.sql
mariadb-dump -h <source-host> -u <user> -p --no-create-info --no-data --triggers --default-character-set=utf8mb4 shop > /backup/shop-triggers.sql
# without generated columns: one dump with --triggers and without --ignore-table-data is enough# 2. Make the MariaDB dump loadable in MySQL
# first line '/*M!999999\- enable the sandbox mode */' (MariaDB 10.5.25, 10.6.18, 10.11.8, 11.x and later)
sed -i '1{/999999.*sandbox mode/d;}' /backup/shop.sql /backup/shop-generated.sql /backup/shop-triggers.sql # GNU sed; on macOS: sed -i '' '1{…;}' …
# sql_mode NO_AUTO_CREATE_USER no longer exists in MySQL 8.0 and later
sed -i 's/,NO_AUTO_CREATE_USER//g; s/NO_AUTO_CREATE_USER,//g' /backup/shop.sql /backup/shop-generated.sql /backup/shop-triggers.sql
# the rows of the table with generated columns go into a staging table first
sed -i -e 's/^INSERT INTO `orders` (/INSERT INTO `stage_orders` (/' /backup/shop-generated.sql
# MariaDB-only syntax (should print nothing)
grep -nE 'CREATE (OR REPLACE )?SEQUENCE|WITH SYSTEM VERSIONING|CREATE PACKAGE|INVISIBLE COLUMN' /backup/shop.sql | head# 3. Load into MySQL
mysql -h <target-endpoint> -u <admin> -p -e 'CREATE DATABASE IF NOT EXISTS `shop` CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;'
mysql -h <target-endpoint> -u <admin> -p --default-character-set=utf8mb4 shop < /backup/shop.sql
# staging table without the generated expressions, the rows, then copy the stored columns only
mysql -h <target-endpoint> -u <admin> -p shop -e 'CREATE TABLE `stage_orders` AS SELECT * FROM `orders` WHERE 1 = 0;'
mysql -h <target-endpoint> -u <admin> -p --default-character-set=utf8mb4 shop < /backup/shop-generated.sql
mysql -h <target-endpoint> -u <admin> -p shop -e 'SET SESSION sql_mode = '\''NO_AUTO_VALUE_ON_ZERO'\'', FOREIGN_KEY_CHECKS = 0; INSERT INTO `orders` (`id`, `customer_id`, `net`, `vat_rate`) SELECT `id`, `customer_id`, `net`, `vat_rate` FROM `stage_orders`; DROP TABLE `stage_orders`;'
mysql -h <target-endpoint> -u <admin> -p --default-character-set=utf8mb4 shop < /backup/shop-triggers.sql
# 4. Accounts: MariaDB password hashes cannot be reused, create them anew
# CREATE USER 'app'@'%' IDENTIFIED WITH caching_sha2_password BY '<new password>';
# GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `shop`.* TO 'app'@'%';MySQL to MariaDB goes the same way in the other direction, with mysqldump and the mariadb client. Check the collations first: MySQL's utf8mb4_0900_* collations are only known to recent MariaDB releases, as aliases of the uca1400 collations, and older ones stop with Unknown collation. MySQL JSON columns become LONGTEXT in MariaDB, and accounts with caching_sha2_password have to be recreated. MariaDB documents replication from MySQL into MariaDB for some versions (from MySQL 8.0 only with recent MariaDB releases, with file-and-position instead of GTIDs and other restrictions); check its compatibility page for your versions before you plan an online switch.
Timing. As for any mysqldump route: offline, with the time of the dump, the corrections (seconds to minutes with sed), the load and the tests.
Binary log replication for a short switch
With replication the new server first gets a consistent copy, then reads the binary log of the old server and applies every change until the switch. The switch itself only stops writes for the time the replica needs to catch up, usually seconds. It works into a new server of the same or the next LTS series (MySQL replicates from an older source to a newer replica within the supported upgrade paths), and into managed services: Amazon RDS and Aurora (external replication with mysql.rds_set_external_source), Azure Database for MySQL (data-in replication with mysql.az_replication_change_master) and Cloud SQL (replication from an external server; Google's Database Migration Service automates the same).
Prerequisites: binary logging on the source with binlog_format = ROW, a unique non-zero server_id on both sides, a primary key on every table (row-based replication without a key can scan the whole table for each change), enough binlog retention for dump, load and catch-up, network access from the target to the source, and the same lower_case_table_names on both sides (Azure Flexible Server uses 1 by default).
- 1. Configure the source:
log_bin,server_id,binlog_format = ROWand, on MySQL,gtid_mode = ONwithenforce_gtid_consistency = ON. Enabling the binary log and changingserver_idneed a restart. - 2. Create a replication account with
REPLICATION SLAVEandREPLICATION CLIENT. - 3. Take a consistent dump with the source position:
mysqldump --source-data=2(MySQL 8.0.26 and later) ormariadb-dump --master-data=2 --gtidwrites the binlog file and position as a comment at the top of the dump. MySQL Shell and mydumper record the same in their metadata. - 4. Load the dump on the target and prepare the parameters as for a normal load (DEFINER,
log_bin_trust_function_creators, time zone). - 5. Start replication from that position with the command of the target:
CHANGE REPLICATION SOURCE TOon your own server, the stored procedures on RDS and Azure. Follow the lag withSHOW REPLICA STATUSuntil it stays near zero. - 6. Switch: stop writes on the source, wait until the replica has applied everything, stop and remove replication, enable the events, and point the application to the target.
# 1. Source my.cnf (log_bin and server_id need a restart)
[mysqld]
server_id = 1 # unique and non-zero on every server
log_bin = mysql-bin
binlog_format = ROW # default on MySQL 8.0+, MariaDB defaults to MIXED
binlog_expire_logs_seconds = 604800 # retention that covers dump, load and catch-up, with a margin
gtid_mode = ON # MySQL; with enforce_gtid_consistency = ON
enforce_gtid_consistency = ON
-- 2. Source: the replication account
CREATE USER 'repl'@'<target address>' IDENTIFIED BY '<password>';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl'@'<target address>';# 3. Consistent dump with the binary log position, then load it on the target
mysqldump --source-data=2 --single-transaction --routines --triggers --events --hex-blob -h <source-host> -u <user> -p shop > /backup/shop.sql
# MariaDB source: mariadb-dump --master-data=2 --gtid …
# GTIDs on: the dump also sets GTID_PURGED; for file-and-position replication into a managed service add --set-gtid-purged=OFF
head -n 50 /backup/shop.sql | grep -E 'CHANGE (REPLICATION SOURCE|MASTER) TO' # the binlog file and position
mysql -h <target> -u <admin> -p shop < /backup/shop.sql-- 4. Start replication on the target
-- own server, MySQL 8.0.23 and later:
CHANGE REPLICATION SOURCE TO SOURCE_HOST='<source-host>', SOURCE_USER='repl', SOURCE_PASSWORD='<password>',
SOURCE_LOG_FILE='<binlog file>', SOURCE_LOG_POS=<position>, GET_SOURCE_PUBLIC_KEY=1;
START REPLICA;
-- own server, MariaDB:
CHANGE MASTER TO MASTER_HOST='<source-host>', MASTER_USER='repl', MASTER_PASSWORD='<password>',
MASTER_LOG_FILE='<binlog file>', MASTER_LOG_POS=<position>;
START SLAVE;
-- Amazon RDS for MySQL 8.4 and later (8.0 and RDS for MariaDB: mysql.rds_set_external_master);
-- last argument 1 = TLS, needed when the replication account uses caching_sha2_password
CALL mysql.rds_set_external_source('<source-host>', 3306, 'repl', '<password>', '<binlog file>', <position>, 1);
CALL mysql.rds_start_replication;
-- Azure Database for MySQL Flexible Server (data-in replication; last argument: CA certificate or '')
CALL mysql.az_replication_change_master('<source-host>', 'repl', '<password>', 3306, '<binlog file>', <position>, '');
CALL mysql.az_replication_start;-- 5. The switch
-- source: stop writes (super_read_only also stops accounts with administrative privileges)
SET GLOBAL super_read_only = ON; -- MariaDB: SET GLOBAL read_only = ON;
SHOW BINARY LOG STATUS; -- MySQL 8.4+; older versions and MariaDB: SHOW MASTER STATUS;
-- target: wait until it has applied everything
SHOW REPLICA STATUS\G -- Seconds_Behind_Source = 0 and the executed position matches the source
STOP REPLICA; RESET REPLICA ALL; -- RDS: CALL mysql.rds_stop_replication; CALL mysql.rds_reset_external_source;
-- Azure: CALL mysql.az_replication_stop; CALL mysql.az_replication_remove_master;
-- events created on the source during replication arrive disabled on the replica: enable them
SELECT event_schema, event_name, status FROM information_schema.events;
-- then point the application to the targetAuthentication of the replication account. On a MySQL 8.0 or later source the replication account uses caching_sha2_password by default. On your own server GET_SOURCE_PUBLIC_KEY=1 or TLS handles that; the RDS procedures need TLS (last argument 1), and Azure accepts a CA certificate in the last argument.
GTIDs. With GTIDs on, mysqldump writes SET @@GLOBAL.GTID_PURGED into the dump, which fails on a target that already has its own GTIDs. For replication by file and position, dump with --set-gtid-purged=OFF. For GTID-based replication use the auto-position variants (SOURCE_AUTO_POSITION=1, mysql.rds_set_external_source_with_auto_position, mysql.az_replication_change_master_with_gtid after az mysql flexible-server gtid reset).
Cloud SQL. Google documents two ways: Database Migration Service (continuous migration job with an initial dump and replication, promoted at the switch) and manual replication from an external server through a source representation instance. Both need the same source settings.
Limits. No DDL during replication without testing it on the replica; events created on the source arrive disabled on the replica; tables without a primary key make the replica slow; MySQL to MariaDB and back only within the narrow combinations each vendor documents. After the switch, going back means reverse replication from the new server to the old one, set up before the switch.
Verification. Before the switch: Seconds_Behind_Source = 0, both replication threads running, and the executed position of the replica equal to the position of the source after writes stopped. Then the checks below.
Amazon RDS and Aurora blue/green deployments
For an upgrade within Amazon RDS for MySQL, RDS for MariaDB or Aurora MySQL, a blue/green deployment does the replication work for you. RDS creates a copy of the production environment (green), with the new engine version and parameter group if you ask for it, and keeps it in sync with binary log replication. The green environment is read-only by default, so you can test against it. At the switchover RDS stops writes, waits until green has caught up, and gives green the names and endpoints of blue; AWS states that this typically takes under a minute. The old environment remains, renamed with -old1.
Prerequisites: binary logging on the blue instance (automated backups on), event_scheduler off in the green parameter group at creation, no external binlog replication into the blue instance, and for a major version upgrade the usual path of one LTS series per step. With a custom option group you cannot specify the major version at creation; create the deployment first and upgrade green afterwards.
- 1. Prepare a parameter group for the new version (with
event_scheduleroff) and run the upgrade checker on a copy or against the blue instance. - 2. Create the deployment with the target engine version and parameter group, and wait until its status is
AVAILABLE. - 3. Test against the green endpoints, read-only, and watch the replica lag.
- 4. Switch over with a timeout (default 300 seconds). If the guardrails find a problem, for example too much replica lag, the switchover is cancelled and blue stays production.
- 5. After the switchover: switch
event_schedulerback on in the new production parameter group if the database has events, check the application, keep the old instance until the go-live is accepted, then delete the deployment and the old instance.
# 1. Create the green environment (it replicates from the current one)
aws rds create-blue-green-deployment --blue-green-deployment-name shop-upgrade \
--source <DB instance or cluster ARN> --target-engine-version <version> \
--target-db-parameter-group-name <parameter group for the new version>
# Aurora MySQL: --target-db-cluster-parameter-group-name for the cluster parameter group
# 2. Follow the status, then test against the green endpoints (read-only)
aws rds describe-blue-green-deployments --blue-green-deployment-identifier <bgd id>
# 3. Switchover: the green environment takes over the names and endpoints
aws rds switchover-blue-green-deployment --blue-green-deployment-identifier <bgd id> --switchover-timeout 300
# 4. After acceptance: remove the deployment, then the old (blue) instance, renamed with -old1
aws rds delete-blue-green-deployment --blue-green-deployment-identifier <bgd id>Limits. Not for moving a database into RDS from elsewhere (use replication or AWS DMS for that); point-in-time restore history does not carry over to the new production instance, so keep the old instance as long as your recovery window requires; the AWS JDBC Driver for MySQL is not supported with blue/green; cascading and cross-region read replicas are not supported. Writing to green before the switchover breaks replication: keep it read-only.
Cloud SQL has a similar blue-green deployment for MySQL (in preview at the time of writing, for example 8.0 to 8.4). On Azure Flexible Server the comparable route is a read replica that you upgrade, then promote after the source has stopped writing.
Checking the result
Check every move the same way, first on the rehearsal and again at the real switch, before the application writes to the target. Write the results down: they are the basis of the go or no-go decision.
- Row counts per table on source and target, at a moment when nothing writes to the source.
- Objects per kind: tables, views, routines, triggers and events, and their DEFINER accounts.
- Character sets and collations of the columns, and a few rows with accents and emoji read through the application.
- Events:
event_scheduler = ONand, after a day,last_executedininformation_schema.events. - Accounts: every application logs in with its own account and driver; no account uses
mysql_native_passwordon 9.x. - Statistics and errors:
ANALYZE TABLEafter the load, the error log of the target, and the slow query log during the first business day. - Business checks: totals, the last order, open invoices: a few queries the application owners know the answer to.
-- Row counts: generate the query on the source, run it on source and target, compare the output
SET SESSION group_concat_max_len = 1000000;
SELECT CONCAT(GROUP_CONCAT(CONCAT('SELECT ''', table_name, ''' AS table_name, COUNT(*) AS row_count FROM `',
table_schema, '`.`', table_name, '`') SEPARATOR '\nUNION ALL '), '\nORDER BY 1;')
FROM information_schema.tables WHERE table_schema = 'shop' AND table_type = 'BASE TABLE';
-- Objects per kind, on source and target
SELECT 'tables' AS kind, COUNT(*) AS n FROM information_schema.tables WHERE table_schema = 'shop' AND table_type = 'BASE TABLE'
UNION ALL SELECT 'views', COUNT(*) FROM information_schema.views WHERE table_schema = 'shop'
UNION ALL SELECT 'routines', COUNT(*) FROM information_schema.routines WHERE routine_schema = 'shop'
UNION ALL SELECT 'triggers', COUNT(*) FROM information_schema.triggers WHERE trigger_schema = 'shop'
UNION ALL SELECT 'events', COUNT(*) FROM information_schema.events WHERE event_schema = 'shop';
-- Character sets and collations of the columns, on source and target
SELECT character_set_name, collation_name, COUNT(*) FROM information_schema.columns
WHERE table_schema = 'shop' AND collation_name IS NOT NULL GROUP BY 1, 2;Do not rely on CHECKSUM TABLE across versions or between MySQL and MariaDB: its result depends on the row format and the version, so a difference does not prove a data difference. For a row-by-row comparison between two MySQL servers, tools such as Percona's pt-table-checksum exist; for most moves, row counts plus business checks are enough.
Error messages and what to change
The errors below stop most MySQL and MariaDB moves. The message tells you which setting or object to look at; the fix is usually on the target or in the dump, not in the tool.
| Symptom or error message | Cause | What to change |
|---|---|---|
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER, SET_USER_ID privilege(s) (8.4 and later: SET_ANY_DEFINER) | Views, routines, triggers or events with a DEFINER of another account, loaded into a managed service | Create the DEFINER accounts first, or remove the DEFINER clauses (sed, or strip_definers in MySQL Shell) |
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled | Binary logging on the target and functions without these characteristics | log_bin_trust_function_creators = 1 in the parameter group or my.cnf |
ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER' | Routines and triggers from MySQL 5.7 or MariaDB carry a SQL mode that MySQL 8.0 removed | Remove NO_AUTO_CREATE_USER from the dump (sed) and from sql_mode in the configuration |
ERROR 3105 (HY000): The value specified for generated column … is not allowed | mariadb-dump writes the values of generated columns | Load those tables through a staging table and copy only the stored columns |
ERROR 1273 (HY000): Unknown collation: 'utf8mb4_uca1400_ai_ci' (or 'utf8mb4_0900_ai_ci' on an older MariaDB) | Collation of one product that the other does not have | Convert the tables to a collation both know on a copy of the source, or replace the name in the dump and test |
ERROR 1067 (42000): Invalid default value for … | '0000-00-00' defaults and a strict sql_mode on the target | Load with the dump's own session sql_mode, or replace zero dates with NULL on the source |
ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded | Account with mysql_native_password on MySQL 8.4 (disabled by default) or 9.x (removed) | ALTER USER … IDENTIFIED WITH caching_sha2_password; check the client connectors |
ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides | util.loadDump with local_infile = OFF on the target (the default since 8.0) | local_infile = 1 during the load, back to 0 afterwards |
ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes or MySQL server has gone away | Rows with large text or blob values | max_allowed_packet = 1073741824 on the target (and --max-allowed-packet for the client) |
ERROR 1298 (HY000): Unknown or incorrect time zone, or times shifted by hours | Named time zone without time zone tables on the target, or another server time zone | Load the zone tables (mysql_tzinfo_to_sql) or use an offset; set the target's time zone to that of the source |
Tables reported as missing, or Different lower_case_table_names settings for server and data dictionary | lower_case_table_names differs between source and target | Initialise or create the target with the source's value; it cannot be changed afterwards |
Unknown command '\-' at line 1 | MariaDB sandbox line read by an older client | Remove the first line of the dump |
ERROR 1064 (42000) near a table or column name | Name that became a reserved word (8.0, 8.4 or 9.x) | Quote it with backticks everywhere, or rename it |
| Events exist but never run | event_scheduler off on the target, or events disabled on a replica | event_scheduler = ON; ALTER EVENT … ENABLE after a replication switch |
@@GLOBAL.GTID_PURGED cannot be changed while loading | Dump from a GTID source loaded into a target with its own GTIDs | Dump with --set-gtid-purged=OFF, or use the GTID reset of the service |
Most of these show up in the structure of the database before the first test load. The free scan flags non-InnoDB tables, zero dates, utf8mb3 columns, DEFINER objects, events and authentication plugins per target version. The full report gives the runbook of the recommended route filled in for your database: the parameters, the dump and load commands with your database name, the corrections for your tables with generated columns and the row-count queries for source and target.
Questions
Should I use mysqldump or MySQL Shell?
For a MySQL source of more than a few gigabytes, MySQL Shell's dump and load is usually much faster because it works in parallel and can resume an interrupted load. For small databases, for MariaDB sources and for MariaDB to MySQL, mysqldump or mariadb-dump is simpler and always available.
Can I upgrade MySQL 5.7 directly to 8.4 or 9.7?
No. Oracle supports only one LTS series per step, also for dump and load and for replication: 5.7 to 8.0, then 8.0 to 8.4, then 8.4 to 9.7. Run the upgrade checker of MySQL Shell before every step.
Can MariaDB replicate into MySQL for a switch without downtime?
No. There is no binary log replication from MariaDB into MySQL 8.0 or later, and no in-place upgrade. The move is a dump with mariadb-dump, a few corrections and a load into MySQL, in a maintenance window.
Why does the load into RDS or Azure stop with ERROR 1227?
The dump contains views, routines, triggers or events with a DEFINER of another account, and the admin user of a managed service may not create objects for other accounts. Create those accounts on the target first, or remove the DEFINER clauses from the dump.
How long is the downtime with replication?
The switch itself usually takes seconds to a few minutes: stop writes, wait until the replica has applied the last changes, stop replication and reconnect the application. The initial copy and the catch-up happen before that, while the old server stays in use.
Can I go back after an in-place upgrade?
Not in place: MySQL cannot be downgraded to an older major version. The way back is a restore of the backup or snapshot taken just before the upgrade, so its restore time belongs in the planning. A new server with replication or a blue/green deployment keeps the old server as the way back.
Read next
- Which migration tool for which database move
Every migration route per source database and target platform – AWS, Azure, Google Cloud or your own server – sorted by the downtime it needs. - Upgrading MySQL 5.7 or 8.0 to 8.4 LTS or 9.7 LTS
MySQL 5.7 and 8.0 are out of support. Upgrade paths to MySQL 8.4 LTS and 9.7 LTS, what breaks (authentication, reserved words, replication syntax), managed MySQL and a free scan. - Database migration routes and downtime: offline, minimal or near-zero
Offline, minimal or near-zero downtime: how to choose a database migration route, what it costs, what breaks online, and the routes per engine.
See which of these tools fits your MySQL or MariaDB database and what will stop it: run the free read-only scan and choose your target. Nothing leaves your browser.
Start the free scan