no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | mysqldump [2015/06/01 22:57] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== mysqldump ====== | ||
+ | * [[MySQL]] | ||
+ | * [[mysqladmin]] | ||
+ | * [[mysqlhotcopy]] | ||
+ | * [[mysqlimport]] | ||
+ | |||
+ | ** Options are processed in the order given.** | ||
+ | |||
+ | Dump a MySQL database that will, on restore, drop the database and it's tables and then recreate them. It will also ignore comments, and set the character set to UTF8. | ||
+ | |||
+ | < | ||
+ | mysqldump --add-drop-database --add-drop-table --default-character-set=utf8 --skip-comments --order-by-primary | ||
+ | </ | ||
+ | |||
+ | ==== Clean Database Dumps ==== | ||
+ | |||
+ | * Two separate exports: schema, then data | ||
+ | * Skip comments | ||
+ | * Skip dump date | ||
+ | * Add DROP TABLE | ||
+ | * Order INSERTs by primary key | ||
+ | * Include column name in INSERT statements | ||
+ | * One INSERT statement per row | ||
+ | |||
+ | Export the schema: | ||
+ | |||
+ | < | ||
+ | mysqldump --no-data --skip-comments --add-drop-table --skip-dump-date -r schema.sql | ||
+ | </ | ||
+ | |||
+ | Export the data: | ||
+ | |||
+ | < | ||
+ | mysqldump --skip-comments --add-drop-table --skip-dump-date --no-create-info --complete-insert --order-by-primary --skip-extended-insert -r data.sql [database] | ||
+ | </ | ||
+ | |||
+ | ==== Restore Options ==== | ||
+ | |||
+ | == Add '' | ||
+ | |||
+ | < | ||
+ | mysqldump --add-drop-database | ||
+ | </ | ||
+ | |||
+ | == Add '' | ||
+ | |||
+ | < | ||
+ | mysqldump --add-drop-table | ||
+ | </ | ||
+ | |||
+ | ==== Schema Options ==== | ||
+ | |||
+ | == Character set == | ||
+ | |||
+ | < | ||
+ | mysqldump --default-character-set=utf8 | ||
+ | </ | ||
+ | |||
+ | == No comments == | ||
+ | |||
+ | < | ||
+ | mysqldump --skip-comments | ||
+ | </ | ||
+ | |||
+ | == Don't set character encoding == | ||
+ | |||
+ | < | ||
+ | mysqldump --skip-set-charset | ||
+ | </ | ||
+ | |||
+ | == Order table dumps by primary key == | ||
+ | |||
+ | Dump each table' | ||
+ | |||
+ | < | ||
+ | mysqldump --order-by-primary | ||
+ | </ | ||
+ | ==== File and Output Options ==== | ||
+ | |||
+ | == Output File == | ||
+ | |||
+ | < | ||
+ | mysqldump -r database.sql | ||
+ | </ | ||
+ | |||
+ | ==== Database Options ==== | ||
+ | |||
+ | **Dump one database** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] database | ||
+ | </ | ||
+ | |||
+ | **Dump database to a file** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] -r database.sql database | ||
+ | </ | ||
+ | |||
+ | **Dump multiple databases** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] -B database database | ||
+ | </ | ||
+ | |||
+ | **Dump all databases** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] -A | ||
+ | </ | ||
+ | |||
+ | ** Schema only ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --no-data | ||
+ | </ | ||
+ | |||
+ | ** Data only ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --no-create-info | ||
+ | </ | ||
+ | |||
+ | ** Ignore comments ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --skip-comments | ||
+ | </ | ||
+ | |||
+ | ** Add DROP DATABASE commands ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --add-drop-database | ||
+ | </ | ||
+ | |||
+ | ** Add DROP TABLE commands ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --add-drop-table | ||
+ | </ | ||
+ | |||
+ | ** Include the column name in INSERT statements ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --complete-insert | ||
+ | </ | ||
+ | |||
+ | ** Each INSERT statement on its own row ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --skip-extended-insert | ||
+ | </ | ||
+ | |||
+ | ** Ignore the dump date ** | ||
+ | |||
+ | < | ||
+ | mysqldump [options] --skip-dump-date | ||
+ | </ | ||
+ | ==== Views ==== | ||
+ | |||
+ | When '' | ||
+ | |||
+ | When restoring the database dump, the views will be created successfully, | ||
+ | |||
+ | Trying to access the view using an SQL statement, or trying to dump the database will throw an error: | ||
+ | |||
+ | < | ||
+ | ERROR 1449 (HY000): The user specified as a definer (' | ||
+ | </ | ||
+ | |||
+ | There are a few ways to avoid this error: | ||
+ | |||
+ | - Delete the lines containing '' | ||
+ | - Create the user on the target database | ||
+ | - Modify the user to be something else | ||
+ | |||
+ | If you want to recreate the user, here's how to get the statement to insert into the '' | ||
+ | |||
+ | < | ||
+ | mysqldump --no-create-info --compact mysql --tables user -w " | ||
+ | </ |