We can use mysqldump to back up various objects in the database. The basic usage is as follows:
Shell>Mysqldump [Options] database [Tables]* If you do not specify any tables, the entire database will be exported.
Mysqldump supports the following options (short option format and long option format ):
- -?, -- Help
- -V, -- version
- -V, -- verbose mode to print more information about the program.
- -H, -- Host = Name the default host is localhost.
- -U, -- user = Name the default value is your UNIX login name.
- -P, -- Password = name if you do not specify the password, mysqldump uses the password from the logon terminal.
- -P, -- Port = # TCP/IP Port number used to connect to a host
- -W, -- where = 'where-condition 'only exports the selected records. Note that the quotation marks are mandatory!
- -X, -- xmldump a database as well formed XML.
- -D, -- no-data does not write any row information of the table. This is useful if you only want to export the structure of a table!
- -S, -- socket = namesocket file to use for connection. The default socket file is.../mysqlpath/tmp/MySQL. Sock.
- -Q, -- quickdon't buffer query, dump directly to stdout. Use mysql_use_result () to obtain it. 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.
- -- Protocol = namethe protocol of connection (TCP, socket, pipe, memory ).
- -- Ignore-table = Name
- -- Add-drop-table: Add a drop TABLE statement before each create statement.
Several common instances:
- Export the entire database
Mysqldump-uroot-P *** db_name> Backup. SQL (including data)
Mysqldump-uroot-P ***-d -- add-drop-Table db_name> Backup. SQL (excluding data)
- Export table structure
Mysqldump-uroot-P *** db_name tbl_name> Backup. SQL
Mysqldump-uroot-P *** db_name t1_name t2_name t3_name> Backup. SQL
We often use the source command or MySQL tool and the <symbol on the shell platform to import data based on the exported file.
- Mysql> Use db_name
Mysql>SourceD:/backup. SQL
- Shell> mysql-uroot-P *** db_name <backup. SQL
We often use mysqldump to make a backup of the entire database, but it is also useful for enriching the information from another MySQL database: mysqldump -- opt database | MySQL -- Host = remote-host-C Database