1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00
Files
til/mysql/dump-a-database-to-a-file.md
2017-06-06 19:36:34 -05:00

23 lines
839 B
Markdown

# Dump A Database To A File
The `mysqldump` client is a handy tool for creating a backup or snapshot of
a MySQL database. The standard use of this command produces an alphabetical
series of statements that comprise the structure and data of the specified
database. It directs all of this to `stdout`. You'll likely want to redirect
it to a file.
```bash
$ mysqldump my_database > my_database_backup.sql
```
The output will include special comments with MySQL directives that disable
things like constraint checking. This is what allows the output to be in
alphabetical order without necessarily violating any foreign key
constraints.
If you need to dump multiple databases, include the `--databases` flag with
a space-separated list of database names. Or dump all of them with
`--all-databases`.
See `man mysqldump` for more details.