Backup using mysqldump
suggest changeSyntax
mysqldump -u [username] -p[password] [other options] db_name > dumpFileName.sqlbacks up a single databasemysqldump -u [username] -p[password] [other options] db_name [tbl_name1 tbl_name2 ...] > dumpFileName.sqlbacks up one or more tablesmysqldump -u [username] -p[password] [other options] --databases db_name1 db_name2 db_name3 ... > dumpFileName.sqlbacks up one or more complete databasesmysqldump -u [username] -p[password] [other options] --all-databases > dumpFileName.sqlbacks up the entire MySQL server
Parameters
| Option | Effect |
|---|---|
-h, --host |
Host name or IP address to connect to. The default is localhost, which on Unix uses a local socket and is not the same as 127.0.0.1. Example: -h localhost |
-u, --user |
MySQL user |
-p, --password |
MySQL password. There must be no space between -p and the password. Example: -pMyPassword. Omitting the password after -p prompts for it. |
--add-drop-database |
Add a DROP DATABASE statement before each CREATE DATABASE statement. Useful when replacing databases on the server. |
--add-drop-table |
Add a DROP TABLE statement before each CREATE TABLE statement. Useful when replacing tables on the server. |
--no-create-db |
Suppress CREATE DATABASE statements. Useful when the databases already exist where you will load the dump. |
-t, --no-create-info |
Suppress CREATE TABLE statements. Useful when you want only row data for identical tables elsewhere. |
-d, --no-data |
Do not write row data. The dump contains CREATE TABLE statements only. Useful for empty template databases. |
-R, --routines |
Include stored procedures and functions. |
-K, --disable-keys |
Disable keys before inserting and enable them afterward. This speeds inserts only for MyISAM tables with nonunique indexes. |
Remarks
The output of a mysqldump operation is a lightly commented file containing sequential SQL statements that are compatible with the version of MySQL utilities that was used to generate it (with attention paid to compatibility with previous versions, but no guarantee for future ones). Thus, the restoration of a mysqldumped database comprises execution of those statements. Generally, this file
DROPs the first specified table or viewCREATEs that table or view- For tables dumped with data (i.e. without the
--no-dataoption) LOCKs the tableINSERTs all of the rows from the original table in one statementUNLOCK TABLES- Repeats the above for all other tables and views
DROPs the first included routineCREATEs that routine- Repeats the same for all other routines
The presence of the DROP before CREATE for each table means that if the schema is present, whether or not it is empty, using a mysqldump file for its restoration will populate or overwrite the data therein.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents