Skip to content
Latchkey

mysqldump Command Reference: Flags, Usage & CI Examples

mysqldump writes a MySQL or MariaDB database to a re-runnable SQL script.

mysqldump connects to a server and emits SQL (CREATE TABLE + INSERT) that recreates one or more databases. It is the standard logical backup tool for MySQL and MariaDB.

Common flags and usage

  • --single-transaction: consistent InnoDB dump without table locks
  • --databases <db...>: dump named databases with USE/CREATE
  • --all-databases: dump every database
  • --no-data / -d: schema only, no rows
  • --routines / --triggers: include stored routines and triggers
  • --add-drop-table: emit DROP TABLE before each CREATE

Example

shell
MYSQL_PWD=${MYSQL_PWD} mysqldump -h 127.0.0.1 -u root --single-transaction app > app.sql

In CI

Add --single-transaction for InnoDB so the dump is consistent without taking a global read lock. Restore the result with the mysql client, not mysqldump. On MySQL 8 dumping needs the PROCESS privilege.

Key takeaways

  • mysqldump produces a re-runnable SQL backup of MySQL/MariaDB.
  • --single-transaction gives a consistent InnoDB snapshot, lock-free.
  • Restore the output with the mysql client.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →