Http://www.cnblogs.com/lyglcheng/archive/2010/04/03/1703630.html
Detailed description of mysqldump backup restoration and mysqldump Import and Export Statements
Mysqldump backup:
Mysqldump-u username-P password-H host database a-W "SQL condition" -- lock-all-tables> path
Case:
Mysqldump-uroot-p1234-hlocalhost db1 A-W "ID in (select ID from B)" -- lock-all-tables> C: \ aa.txt
Restore mysqldump:
Mysqldump-u username-P password-H host database <path
Case:
Mysql-uroot-p1234 db1 <c: \ aa.txt
Mysqldump export by conditions:
Mysqldump-u username-P password-H host database a -- where "Condition Statement" -- no-Table creation> path
Mysqldump-uroot-p1234 dbname A -- where "tag = '88 '" -- no-create-Info> C: \ A. SQL
Mysqldump:
Mysqldump-u username-P password-H host database <path
Case:
Mysql-uroot-p1234 db1 <c: \ a.txt
Mysqldump export table:
Mysqldump-u username-P password-H host database table
Case:
Mysqldump-uroot-P sqlhk9 A -- no-Data
Some main parameters of mysqldump
-- Compatible = Name
It tells mysqldump that the exported data will be compatible with the database or the old MySQL server. The values can be ANSI, mysql323, mysql40, PostgreSQL, Oracle, MSSQL, DB2, MaxDB, no_key_options, no_tables_options, and no_field_options. Separate them with commas. Of course, it does not guarantee full compatibility, but is as compatible as possible.
-- Complete-insert,-C
The exported data adopts the complete insert method containing the field name, that is, all values are written in one row. This can improve the insertion efficiency, but may be affected by the max_allowed_packet parameter, resulting in insertion failure. Therefore, you need to use this parameter with caution. At least I do not recommend this parameter.
-- Default-character-set = charset
Specifies the character set used for data export. If the data table does not use the default Latin1 character set, this option must be specified during data export. Otherwise, garbled characters will occur after data is imported again.
-- Disable-keys
Tell mysqldump to add/* at the beginning and end of the insert statement /*! 40000 alter table table disable keys */; And /*! 40000 alter table table enable keys */; Statement, which greatly improves the speed of the insert statement because it re-creates the index after all data is inserted. This option is only applicable to MyISAM tables.
-- Extended-insert = true | false
By default, mysqldump enables the -- complete-insert mode, so if you do not want to use it, use this option to set its value to false.
-- Hex-blob
Export binary string fields in hexadecimal format. This option is required if binary data exists. The affected field types include binary, varbinary, and blob.
-- Lock-all-tables,-x
Before starting the export, submit a request to lock all tables in all databases to ensure data consistency. This is a global read lock and the -- Single-transaction and -- lock-Tables options are automatically disabled.
-- Lock-tables
It is similar to -- lock-all-tables, but instead of locking all tables in the database. This option is only applicable to MyISAM tables. For InnoDB tables, you can use the -- Single-transaction option.
-- No-create-Info,-T
Only export data without adding the create table statement.
-- No-data,-d
Only the database table structure is exported without exporting any data.
-- OPT
This is just a quick option, it is equivalent to adding the -- add-drop-tables -- add-locking -- create-option -- disable-keys -- extended-insert -- lock-tables -- quick -- Set-charset option at the same time. This option allows mysqldump to export data quickly and export data back quickly. This option is enabled by default, but can be disabled with -- skip-OPT. Note: If the -- quick or -- opt option is not specified when running mysqldump, the entire result set is stored in the memory. If you export a large database, problems may occur.
-- Quick,-Q
This option is useful when exporting large tables. It forces mysqldump to retrieve records from the Server query and output them directly instead of caching all records into the memory.
-- Routines,-R
Export stored procedures and user-defined functions.
-- Single-transaction
This option submits a begin SQL statement before exporting data. Begin does not block any applications. Program The Database Consistency during export can be ensured. It is only applicable to transaction tables, such as InnoDB and bdb.
This option and the -- lock-tables option are mutually exclusive, Because lock tables will implicitly commit any pending transactions.
To export a large table, use the -- quick option.
-- Triggers
Export the trigger at the same time. This option is enabled by default. Use -- skip-triggers to disable it.
For details about other parameters, see the manual. I usually use the following SQL to back up the MyISAM table:
/Usr/local/MySQL/bin/mysqldump-uyejr-pyejr"
-- Default-character-set = utf8 -- Opt -- extended-insert = false"
-- Triggers-r -- Hex-blob-x db_name> db_name. SQL
Use the following SQL to back up the InnoDB table:
/Usr/local/MySQL/bin/mysqldump-uyejr-pyejr"
-- Default-character-set = utf8 -- Opt -- extended-insert = false"
-- Triggers-r -- Hex-blob -- Single-transaction db_name> db_name. SQL
In addition, if you want to implement online backup, you can also use the -- master-data parameter, as shown below:
/Usr/local/MySQL/bin/mysqldump-uyejr-pyejr"
-- Default-character-set = utf8 -- Opt -- master-Data = 1"
-- Single-transaction -- flush-logs db_name> db_name. SQL
It only requests the lock table at the beginning, then refreshes the BINLOG, and then adds the change master statement to the exported file to specify the BINLOG location of the current backup, if you want to restore the file to slave, you can use this method.
1.2 restore
The file backed up with mysqldump is an SQL script that can be directly imported. There are two ways to import data.
Directly use the mysql client
For example:
/Usr/local/MySQL/bin/MySQL-uyejr-pyejr db_name <db_name. SQL
Use the source syntax (The experiment failed !!!)
In fact, this is not a standard SQL syntax, but a function provided by the mysql client, for example:
Source/tmp/db_name. SQL;
Here, you must specify the absolute path of the file and the file must be read by the mysqld running user (such as nobody.