To back up every MySQL database on a server, use mysqldump --all-databases (or a physical snapshot tool like Percona XtraBackup) with a consistent snapshot and binary logging enabled; to restore, replay the dump into a server with matching major version and character-set settings, then apply binary logs for point-in-time recovery. The key condition is consistency: a backup is only restorable if it was taken from a quiescent or transactionally consistent state and you have tested the restore path before you need it.

That short answer hides most of the hard parts. "Every database" is not one command in practice—it means the user schemas, the mysql system tables that hold accounts and grants, and the sys/performance_schema internals, each of which behaves differently under dump and restore. It also means deciding between logical dumps (portable, slow, easy to edit) and physical copies (fast, version-sensitive, large). And it means planning for the difference between restoring everything to the same server and rebuilding onto a fresh one.

This guide walks through the whole cycle in the order you should actually do it: prerequisites, the backup, verification, the restore, point-in-time recovery, and the failure modes that turn a "backup" into a folder of useless bytes.

What "every database" actually includes

A MySQL server ships with four kinds of schemas, and a complete backup strategy has to account for all of them:

User databases you created—your application data. These are the obvious target. The mysql schema, which stores user accounts, privileges, password hashes, and stored routines owned by the system. Dumping it is what lets a restored server recognize the same users and grants. sys, a set of views and helpers over performance_schema and information_schema. It is largely recreated automatically and generally should not be dumped wholesale. performance_schema and information_schema are in-memory or generated metadata; they are not backed up as data and are rebuilt at startup.

There is also non-schema state that a database dump does not capture: the binary log files, the replication configuration, server configuration files (my.cnf/my.ini), SSL certificates, and any files the storage engine keeps outside the data directory. "Every database" in the strict sense means every schema; "every piece of state needed to rebuild the server" is a larger set, and knowing which one you mean determines your tooling.

A useful distinction when planning: a logical backup reproduces SQL statements or table rows and restores through the server, so it survives version upgrades and platform changes but can be slow on large datasets. A physical backup copies data files, so it is fast to restore but tied to the storage engine, file format, and often the exact major version.

Prerequisites before you touch a backup command

Do these first; skipping them is the most common cause of a backup that looks fine and restores wrong.

1: Know your version. Run SELECT VERSION();. Note the exact major and minor version. Logical dumps from a newer server often will not load cleanly into an older one, and physical backups are even stricter. Plan restores to the same major version, or to a newer one you have actually tested. 2: Confirm binary logging. Run SHOW VARIABLES LIKE 'log_bin';. If it returns ON, you can do point-in-time recovery later. If it is OFF, your logical backups only recover to the moment of the dump. 3: Check the storage engine. SHOW TABLE STATUS or query information_schema.TABLES for ENGINE. InnoDB supports consistent, hot backups; MyISAM does not lock safely under load and needs table locks to be consistent. 4: Provision an account with the right privileges. For a full logical dump you need SELECT, SHOW VIEW, TRIGGER, LOCK TABLES (if using --single-transaction you still need consistent-read access), RELOAD or FLUSH_TABLES for some options, and PROCESS to see all databases. A dedicated backup user is better than reusing root. 5: Decide where the backup lands. Never write a backup to the same volume as the data directory if you can avoid it—disk failure takes both. Copy off-host as soon as the dump finishes. 6: Free disk space. A logical dump can approach the size of the data itself; a physical backup can be larger before compression. Check df -h on the target.

A practical check for privileges and scope is to list the databases explicitly: SHOW DATABASES; shows what exists, and comparing that list to what your backup user can read catches permission gaps before they matter.

Backing up every database with mysqldump

The canonical logical command for all schemas is:

Walk through the flags, because each one exists for a reason:

--all-databases dumps every schema, including mysql, sys, and the user databases. It does not include performance_schema or information_schema data, which is correct. --single-transaction takes a consistent snapshot of InnoDB tables inside one transaction without locking them for the whole dump. This is what makes a hot backup consistent. It does not protect MyISAM tables—those need --lock-tables (the default) or a maintenance window. --routines and --triggers capture stored procedures, functions, and triggers. Without these flags you silently lose application logic that lives in the database. --events captures scheduled events. Easy to forget, and their absence only shows up when a job that should run doesn't. --set-gtid-purged=OFF matters on servers using GTIDs; leaving GTID state in a dump can cause conflicts when you restore onto a different server or replay into an existing one. Set it deliberately based on your topology. --default-character-set=utf8mb4 avoids mojibake when the server default and the client default differ.

Two practical refinements. First, compress on the fly to save space and transfer time: pipe through gzip (... | gzip > all_databases.sql.gz) and restore with gunzip -c all_databases.sql.gz | mysql .... Second, split per-database dumps if you want to restore one schema without touching others. A loop over SHOW DATABASES producing one file per schema gives you finer restore granularity, at the cost of more files to manage.

For large datasets, mysqldump becomes slow because it reads and rewrites every row. At that point physical tools earn their keep.

Physical backups when logical dumps are too slow

When a database is hundreds of gigabytes, dumping and reloading through SQL can take hours. Physical backup tools copy or snapshot InnoDB files while tracking the log sequence, which restores far faster.

Percona XtraBackup is the well-known open-source option for InnoDB hot backups; it copies data files while the server runs and applies redo logs to make the copy consistent. It is version-sensitive: pair the tool version with the server major version. MySQL Enterprise Backup is Oracle's commercial equivalent for the same job. Filesystem or volume snapshots (LVM, ZFS, cloud block-storage snapshots) can be fast if you quiesce writes first. The catch is the same as MyISAM: without flushing and locking, an unquiesced snapshot can be crash-inconsistent. Run FLUSH TABLES WITH READ LOCK (or rely on your engine's consistent-snapshot support), take the snapshot, then release the lock—and confirm your storage layer actually supports atomic snapshots. Replication as a backup source is common: keep a replica and take backups from it, so production load is unaffected. The replica must be in sync; verify with SHOW REPLICA STATUS (or SHOW SLAVE STATUS on older versions) and confirm Seconds_Behind_Source is zero before you start.

Physical backups capture every schema including mysql, but they do not capture server configuration or binlog files unless you copy those separately. For a full disaster-recovery set, back up my.cnf, the binlog directory, and any TLS material alongside the data files.

Verifying a backup before you trust it

An untested backup is a hypothesis. The cheapest check is to confirm the dump is complete and loadable:

1: Check size and tail. A dump that ends abruptly is the classic silent failure. For a .sql file, the last lines should be the closing statements; for a gzip stream, gzip -t confirms integrity without decompressing fully. 2: Restore into a scratch server. Spin up a disposable MySQL instance of the same major version and load the dump. This is the only real proof. It also measures restore time so you know your recovery window. 3: Spot-check row counts and a few tables. Compare SELECT COUNT(*) on a couple of large tables between source and restored copy, and confirm a known row exists. 4: Confirm routines and triggers survived. Query information_schema.ROUTINES and information_schema.TRIGGERS on the restored copy; their absence is easy to miss until an application hits a missing procedure.

Automate step 2 on a schedule if you can. A nightly restore of the latest dump into a throwaway instance, followed by a few assertions, converts "we have backups" into "we have restorable backups." That distinction is the entire point of the exercise.

Stop condition: if a restore into a scratch instance fails with errors you cannot map to a known cause—corruption, incompatible version, missing tablespace—do not attempt to force it onto production. Escalate to whoever owns the database platform or to vendor support, and preserve the failing dump and logs for diagnosis.

Restoring every database: full logical restore

Restoring an all-databases dump is a sequence, and order matters.

Prerequisites: a running MySQL server of the compatible major version, an account with SUPER/SYSTEM_VARIABLES_ADMIN and full privileges sufficient to recreate users and grants, and enough disk space for the data plus indexes.

1: Stop application writes or point the application at nothing during the restore. Loading into a live database under write load produces inconsistencies and duplicate-key errors. 2: Start from a clean server if possible. Restoring an --all-databases dump onto a server that already has those schemas can collide on existing tables, users, and routines. On a fresh instance this is not a problem; on an existing one, either drop the target schemas first (after backing them up) or restore into a separate instance. 3: Load the dump: For a compressed dump: gunzip -c all_databases.sql.gz | mysql -u root -p. 4: Watch for errors. By default mysql stops on the first error. For a clean rebuild that is what you want, because continuing past an error produces a half-restored server. Use --force only when you have a specific reason to continue and will review the error log afterward. 5: Reload or re-point the application once the restore reports success.

Success check: SHOW DATABASES; lists every expected schema; row counts on key tables match the source at dump time; a known query returns expected results; and the application connects and passes a smoke test. If you restored onto a new server, verify accounts by logging in as a non-root application user—restoring the mysql schema brings those accounts back, but confirm their passwords and hosts behave as intended.

Restoring onto a different server or version

Restoring to a new machine is the disaster-recovery scenario, and it has extra wrinkles:

Version skew. Loading a dump from 8.0.x into 8.4 usually works through the upgrade path, but the reverse often does not. If you must move backward, test the specific dump; some syntax and system-table differences will not load. mysql schema conflicts. The dump contains CREATE USER and GRANT statements. On a fresh server those succeed; on one with existing accounts they can error on duplicates. Restoring the mysql schema wholesale onto an existing server is risky—consider restoring user data and reapplying grants separately. DEFINER clauses. Routines and views carry a DEFINER (the account that created them). If that account does not exist on the target server, the objects may load but fail at execution with a definer error. Either create the account first or adjust definers deliberately. sql_mode and character set. Differences between source and target can change how data loads (strict vs. non-strict mode can turn warnings into errors). Set sql_mode and the character set to match before loading. Time zone tables. If your application uses CONVERT_TZ, the time zone tables in the mysql schema must be populated on the target (mysql_tzinfo_to_sql on Unix-like systems), or conversions return NULL.

The general rule: restore user data freely across versions, but treat the mysql schema, definers, and configuration as things to reconcile consciously rather than copy blindly.

Point-in-time recovery after the restore

A full restore takes you to the moment of the dump. Anything written after that is lost unless you have binary logs. Point-in-time recovery replays them.

Prerequisites: binary logging was on at dump time and continuously since, and you have the binlog files from the dump's position forward.

1: Find the position or GTID at dump time. mysqldump with --master-data=2 (or --source-data=2 in newer versions) writes a commented CHANGE MASTER/CHANGE REPLICATION SOURCE line into the dump recording the binlog file and position. If your dump lacks it, you cannot reliably find the starting point from the dump alone. 2: Restore the full dump as above. 3: Replay the binlogs from that recorded position up to the moment before the incident: With GTIDs, use --skip-gtids as appropriate for your topology and replay by GTID set. 4: Stop replay at the recovery target. For "undo a bad delete," identify the statement to exclude and stop just before it—mysqlbinlog supports start/stop times and positions for exactly this. Replaying past the bad statement reintroduces the damage.

Success check: a row or record you know was created after the dump and before the incident is present in the restored server, and the bad change is absent. Verify both directions, because it is easy to stop too early and lose legitimate writes.

This is where "restore every database" gets genuinely subtle: the mysql schema in the dump is a snapshot of grants at dump time, but later GRANT/REVOKE statements live in the binlog. Replaying binlogs applies those too, which is usually what you want—but if you restored the mysql schema onto a server with different accounts, replay can conflict. Plan the account story before you start.

Common failures and how to avoid them

InnoDB consistency assumed where it doesn't exist. --single-transaction only covers InnoDB. Mixed engines with MyISAM tables under active writes need locking or a maintenance window, or the dump is inconsistent. Silent truncation. A full disk during dump leaves a file that looks complete until you try to load it. Always gate the job on the command's exit status and check the file tail; never treat "no error printed" as success. Missing routines, triggers, or events. The flags are off by default in older server versions. If you enabled them, verify on restore; if a restored application throws "procedure does not exist," this is the first suspect. Restoring the mysql schema onto a live server. Duplicate-account errors and unexpected privilege changes. Prefer a fresh instance for full restores, or separate data restore from account reconciliation. Definer errors after restore. The account that owned a routine is gone. Recreate it or rewrite definers as part of the restore plan. Binlog gaps. If binlogging was disabled for a window, point-in-time recovery silently skips writes from that period. Monitor that log_bin stays on and that binlogs are retained long enough to cover your recovery window. Backups on the same disk. A single volume failure destroys both data and backup. Copy off-host immediately and confirm the copy completed.

Troubleshooting order, from cheapest to most invasive: check the job's exit code and file integrity first (reversible), then load into a scratch server (reversible), then attempt a restore onto a spare instance, and only then consider production. If corruption or an unexplained load failure appears at the scratch stage, stop and involve a database professional rather than iterating directly against production.

Building a repeatable routine

The commands are simple; the discipline is the work. A dependable routine looks like this: schedule mysqldump --all-databases --single-transaction --routines --triggers --events on a replica, compress and copy off-host, run a nightly automated restore into a scratch instance with a few assertions, retain binary logs for at least the restore window you promise, and keep my.cnf and TLS material in the same backup set. Document the exact commands and the version they were tested against, because restore instructions written for one release can quietly break on the next.

A rough sizing note, clearly an estimate: logical dump time scales with total data size and is typically bound by disk read speed and single-threaded dump processing, so a dataset of tens of gigabytes may dump in minutes while hundreds of gigabytes can take hours; physical snapshots are bounded more by copy bandwidth. Measure your own restore time during verification—that number, not the dump time, defines your real recovery window.

The question "how do I back up and restore every MySQL database" is really two questions: how do I capture a consistent, complete copy, and how do I prove it restores. Answer the second before you need it, and the first takes care of itself.