MySQL tool: basic usage of mysqldump

Source: Internet
Author: User

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 ):

  1. -?, -- Help
  2. -V, -- version
  3. -V, -- verbose mode to print more information about the program.
  4. -H, -- Host = Name the default host is localhost.
  5. -U, -- user = Name the default value is your UNIX login name.
  6. -P, -- Password = name if you do not specify the password, mysqldump uses the password from the logon terminal.
  7. -P, -- Port = # TCP/IP Port number used to connect to a host
  8. -W, -- where = 'where-condition 'only exports the selected records. Note that the quotation marks are mandatory!
  9. -X, -- xmldump a database as well formed XML.
  10. -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!
  11. -S, -- socket = namesocket file to use for connection. The default socket file is.../mysqlpath/tmp/MySQL. Sock.
  12. -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.
  13. -- Protocol = namethe protocol of connection (TCP, socket, pipe, memory ).
  14. -- Ignore-table = Name
  15. -- Add-drop-table: Add a drop TABLE statement before each create statement.

 

Several common instances:

  1. 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)
  2. 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.

  1. Mysql> Use db_name
    Mysql>SourceD:/backup. SQL
  2. 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.