How to back up MySQL databases: mysqldump for logical backups, MySQL Shell’s dump utilities, binary log-based point-in-time recovery, and backup best practices for production systems.
Use this file to discover all available pages before exploring further.
VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
A MySQL backup strategy has two parts: taking a consistent snapshot of your data (the full backup) and having a way to replay changes made after that snapshot (point-in-time recovery). The right tools depend on database size, acceptable recovery time, and how much data you can afford to lose.
mysqldump exports data as SQL statements. It’s the most portable format and works for databases of any size, though it’s slower to restore than binary backups for large datasets.Back up a single database:
Full backups only protect you to the point of the last backup. Binary logging lets you replay every change made after the backup was taken.Requirements:
Binary logging enabled (log_bin = ON)
--source-data=2 used when taking the backup (records the starting binlog position)
Workflow:
Restore the full backup:
mysql -u root -p < myapp_backup.sql
Find the binlog starting position from the dump file:
head -50 myapp_backup.sql | grep "SOURCE_LOG_FILE"-- CHANGE REPLICATION SOURCE TO SOURCE_LOG_FILE='mysql-bin.000003', SOURCE_LOG_POS=154;
Replay binary logs up to the point just before the event you want to undo:
MySQL Shell (mysqlsh) provides faster dump and load utilities than mysqldump. They use parallel threads and produce compressed output, making them practical for large databases.
# Dump a single schemamysqlsh root@localhost -- util dump-schemas '["myapp"]' --outputUrl=/backups/myapp# Load it backmysqlsh root@localhost -- util load-dump /backups/myapp
MySQL Shell dump utilities compress output by default (zstd) and can parallelize both dump and load across multiple CPU cores. For databases larger than a few GB, the speed difference over mysqldump is significant.
mysqldump is still the go-to for portability and simplicity. MySQL Shell dump has effectively replaced mysqlpump for large databases — it’s faster, produces smaller files, and supports MySQL 8.0+. mysqlpump is deprecated in MySQL 8.4 and should not be used for new backup scripts.For production databases over ~50 GB where restore time matters, Percona XtraBackup or MySQL Shell dump are the practical choices.
Does --single-transaction work with all storage engines?
No. --single-transaction uses a consistent read snapshot, which only InnoDB supports. MyISAM tables in the same database are still locked with LOCK TABLES during the dump. If you have mixed engines, --single-transaction alone isn’t sufficient for a fully consistent dump.
At minimum: daily backups for 7–14 days, weekly backups for 4 weeks, monthly backups for a year. Retention depends on regulatory requirements and how far back you might need to recover. Binary logs should be retained long enough to cover the gap between your oldest retained backup and now.
Only if the server is shut down first (cold copy). A running MySQL server writes data files in a way that’s not safe to copy directly — you’ll get a corrupt backup. For hot backups without stopping the server, use MySQL Shell’s dump utility or Percona XtraBackup.