The mysqldump command is a built-in database backup, restoration, import, and export command in mysql. Next I will introduce you to the usage of the mysql mysqldump command in data import and export in applications. For details, refer.
The basic usage of mysqldump is as follows:
Shell> mysqldump [OPTIONS] database [tables]
If you do not specify any tables, the entire database will be exported.
Run mysqldump -- help to obtain the option table supported by your mysqldump version.
Note: If you run mysqldump without the -- quick or -- opt option, mysqldump loads the entire result set to the memory before the export result. If you are exporting a large database, this may be a problem.
Mysqldump supports the following options:
-- Add-locks
Add lock tables and unlock table before each TABLE is exported. (To make it faster to insert data to MySQL ).
-- Add-drop-table
Add a drop table before each create statement.
-- Allow-keywords
Names of columns allowed to be created as keywords. This is done by the table name prefix on each column name.
-C, -- complete-insert
Use the complete insert Statement (with the column name ).
-C, -- compress
If both the client and server support compression, all information is compressed between the two.
-- Delayed
Use the insert delayed command to INSERT rows.
-E, -- extended-insert
Use the new multiline INSERT syntax. (A more compact and faster insert statement is provided)
-#, -- Debug [= option_string]
Tracking Program usage (for debugging ).
-- Help
Displays a help message and exits.
-- Fields-terminated-by =...
-- Fields-enclosed-by =...
-- Fields-optionally-enclosed-by =...
-- Fields-escaped-by =...
-- Fields-terminated-by =...
These options are used with-T options and have the same meaning as the load data infile clause.
Load data infile syntax.
-F, -- flush-logs
Wash Out the log files on the MySQL server before starting the export.
-F, -- force,
Even if we get an SQL error while exporting a table, continue.
-H, -- host = ..
Export data from the MySQL server on the named host. The default host is localhost.
-L, -- lock-tables.
Lock all tables for start export.
-T, -- no-create-info
Create table statement)
-D, -- no-data
No row information is written to the table. If you only want to export the structure of a table, this is very useful!
-- Opt
Same as -- quick -- add-drop-table -- add-locks -- extended-insert -- lock-tables.
You should be given the fastest export possible for reading a MySQL server.
-Pyour_pass, -- password [= your_pass]
The password used to connect to the server. If you do not specify "= your_pass", mysqldump requires a password from the terminal.
-P port_num, -- port = port_num
The TCP/IP Port used to connect to a host. (This is used to connect to a host other than localhost because it uses Unix sockets .)
-Q, -- quick
Directly export the data to stdout without buffering the query; Use mysql_use_result () to do it.
-S/path/to/socket, -- socket =/path/to/socket
The socket file used when connecting to localhost (which is the default host.
-T, -- tab = path-to-some-directory
For each given table, CREATE a table_name. SQL file that contains the SQL CREATE command and a table_name.txt file that contains data. Note: This only works when mysqldump runs on the same machine where the mysqld daemon is running .. The format of the txt file is determined by the options -- fields-xxx and -- lines -- xxx.
-U user_name, -- user = user_name
The username used by MySQL to connect to the server. The default value is your Unix login name.
-O var = option, -- set-variable var = option to set the value of a variable. Possible variables are listed below.
-V, -- verbose
Lengthy mode. Print out more information about the program.
-V, -- version
Print the version information and exit.
-W, -- where = 'where-condition'
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:
The Code is as follows: |
Copy code |
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:
The Code is as follows: |
Copy code |
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
The Code is as follows: |
Copy code |
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:
The Code is as follows: |
Copy code |
Mysql-uroot-p1234 db1 <c: a.txt |
Mysqldump:
Mysqldump-u username-p password-h host database table
Case:
The Code is as follows: |
Copy code |
Mysqldump-uroot-p sqlhk9 a -- no-data |