Skip to content

Database export — mysqldump vs Percona xtrabackup

Picking the right database export tool for a migration. Logical dumps versus physical hot backups, when each one fails, and what to pick for which workload.

The migration plan says “export the database.” On a 4 GB WordPress site, mysqldump finishes in three minutes and nobody asks a second question. On a 180 GB WooCommerce database with active checkouts, the same command runs for two hours, locks tables that the live store needs, and produces a SQL file the destination can’t import in the maintenance window. The export tool is a sizing decision, not a default.

What’s happening

mysqldump produces a logical export — a stream of INSERT statements the destination replays row by row. It is portable across MySQL versions and storage engines, but it reads every row through the server, holds metadata locks that block DDL, and on InnoDB it requires either --single-transaction (which serializes against long-running writes) or a lock. Restore time scales linearly with row count plus index rebuild time, and index rebuild on a 100M-row table is measured in hours.

Percona xtrabackup (now xtrabackup from Percona XtraBackup) produces a physical backup — a copy of the InnoDB data files plus a redo log stream captured during the copy. It does not block writes, scales with on-disk size rather than row count, and restores by file copy instead of replay. The cost: source and destination must run compatible MySQL/Percona versions and the same storage engine layout.

How to verify

Before choosing, measure:

mysql -e "SELECT table_schema, SUM(data_length+index_length)/1024/1024/1024 AS size_gb FROM information_schema.tables GROUP BY table_schema ORDER BY size_gb DESC;"
mysql -e "SHOW ENGINE INNODB STATUS\G" | grep -i "history list length"
mysql -e "SHOW VARIABLES LIKE 'version%';"

Note total InnoDB data size, the largest table’s row count, and the source MySQL version. Confirm the destination version matches or is one minor version newer. Check whether the workload has long-running transactions — a high InnoDB history list means --single-transaction will balloon undo and slow the dump dramatically.

The fix

For databases under roughly 20 GB on a single host, mysqldump --single-transaction --quick --routines --triggers against a read replica or during a low-write window is straightforward. Pipe directly through SSH to the destination: mysqldump … | ssh dest 'mysql target_db' to avoid intermediate disk. For anything larger, or any workload that cannot tolerate the lock window, use xtrabackup --backup --stream=xbstream | ssh dest 'xbstream -x -C /var/lib/mysql/', then xtrabackup --prepare on the destination before starting MySQL. Always verify the restore on the destination — row counts per table, CHECK TABLE, and a representative read query — before scheduling the actual cutover.

We pick the export path per-workload during Migration preflight — book a database migration review.