Why Backups Matter
Hardware fails, people run DROP TABLE by mistake, and attackers encrypt data. A backup you have never restored is only a hope. Plan three things: how often you back up, where copies are stored (not only on the same server), and how fast you can restore.
Logical vs Physical Backups
Logical (mysqldump, mysqlpump, MySQL Shell dump) | Physical (file copy: Percona XtraBackup, MySQL Enterprise Backup, snapshots) | |
|---|---|---|
| What it saves | SQL statements | The data files |
| Speed on big data | Slower, especially to restore | Much faster |
| Portable between versions | Yes | Usually same major version |
| Good for | Small and medium databases, migrations | Large production databases |
Taking a Dump
This ran on a real MySQL 8.0 server (mysqldump 8.0). The command and the main part of its output for a tiny database:
The lines starting with /*! and -- (version comments and timestamps) were removed here to keep it short. Notice the file contains DROP TABLE IF EXISTS, CREATE TABLE and INSERT statements: it is a plain SQL script.
Important Options
| Option | Why |
|---|---|
--single-transaction | Consistent snapshot of InnoDB tables without locking them |
--routines --triggers --events | Include stored programs (triggers are included by default, routines and events are not) |
--databases db1 db2 / --all-databases | Include CREATE DATABASE |
--no-data | Structure only |
--set-gtid-purged=OFF | Avoid GTID statements when restoring to a different server |
--hex-blob | Safe dumping of binary data |
--source-data=2 (8.0.26+) | Write the binary log position in a comment, for point-in-time recovery |
Restoring
The script above was also run: the dump was loaded into a new database and a row count was compared. The real result was 1 customer restored, matching the source. Always verify a restore like this, with row counts or checksums (CHECKSUM TABLE t).
Result:
| row_count | id_sum |
|---|---|
| 2 | 3 |
Binary Logs and Point-in-Time Recovery
A nightly dump alone loses everything since the last dump. The binary log records every change. Restore the last backup, then replay the log up to just before the mistake:
These commands need server log files and a real incident, so they are shown, not run. Check that logging is on:
Result:
| binary_log_enabled | format | keep_seconds |
|---|---|---|
| 1 | ROW | 2592000 |
A Practical Backup Plan
- Nightly logical or physical backup, kept for at least 7-30 days.
- Binary logs retained at least until the next full backup, copied off the server.
- Copies in a second location (another region or storage account).
- Backups encrypted, with limited access.
- A restore test every month into a scratch server, with a written checklist.
Common Beginner Mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Never testing a restore | Backup is unusable when needed | Scheduled restore tests |
Backing up without --single-transaction | Inconsistent data or table locks | Add it for InnoDB |
| Forgetting routines and events | Missing stored programs | --routines --events |
| Backups stored only on the same disk | Lost together with the server | Off-server copies |
| Passwords on the command line | Visible in the process list | Use -p prompt or a protected option file |
Using mysqldump for multi-terabyte data | Takes days to restore | Physical backup tools |
Practice
- Dump a small database and restore it to a new name.
- Compare row counts of both.
- Dump only the structure with
--no-data. - Write down your recovery steps for "someone dropped a table at 14:03".
Conclusion
Use mysqldump --single-transaction --routines --triggers --events for small to medium databases, keep binary logs for point-in-time recovery, copy backups off the server and test restoring them regularly.

