mysqldump is the standard MySQL command-line tool for creating logical backups. It generates a SQL file containing DROP TABLE, CREATE TABLE, and INSERT statements that recreate the database from scratch.
Common mysqldump Options
- --single-transaction: For InnoDB tables, takes a consistent snapshot without locking tables. Essential for production backups.
- --routines: Includes stored procedures and functions
- --triggers: Includes triggers (included by default)
- --no-data: Exports only the schema, no row data
- --where: Exports only rows matching a condition
- --tables: Exports only specified tables
InnoDB vs MyISAM
For InnoDB tables, always use --single-transaction. For MyISAM tables, use --lock-tables instead (the default). Mixing them requires care to avoid inconsistencies.