Mysqlmysqldump Database Backup command Introduction

Source: Internet
Author: User
Tags sql error
This article collects a large number of statements and examples about the mysqldump command. It also describes usage instructions on foreign websites. For more information, see.

This article collects a large number of statements and examples about the mysqldump command. It also describes usage instructions on foreign websites. For more information, see.

The Code is as follows:
Dump-hhostname-uusername-ppassword databasename> backupfile. SQL

Back up MySQL in the format of a table with deletion. Back up MySQL in the format of a table with deletion. This allows the backup to overwrite the existing database without manually deleting the original database.

Mysqldump --- add-drop-table-uusername-ppassword databasename> backupfile. SQL compresses and backs up MySQL databases directly.

The Code is as follows:
Mysqldump-hhostname-uusername-ppassword databasename | gzip> backupfile. SQL .gz

Back up a MySQL database table

The Code is as follows:
Mysqldump-hhostname-uusername-ppassword databasename specific_table1 specific_table2> backupfile. SQL

Back up multiple MySQL databases at the same time

The Code is as follows:
Mysqldump-hhostname-uusername-ppassword -- databases databasename1 databasename2 databasename3> multibackupfile. SQL

Back up database structures only

The Code is as follows:
Mysqldump -- no-data -- databases databasename1 databasename2 databasename3> structurebackupfile. SQL

Back up all databases on the server

The Code is as follows:

Mysqldump -- all-databases allbackupfile. SQL command for restoring MySQL database

Mysql-hhostname-uusername-ppassword databasename <backupfile. SQL restores the compressed MySQL database

Gunzip <backupfile. SQL .gz | mysql-uusername-ppassword databasename transfers the database to the new server

Mysqldump-uusername-ppassword databasename | mysql -- host = *. *-C databasename compression backup

Back up and Compress With gzip:

The Code is as follows:

Mysqldump <mysqldump options> | gzip> outputfile. SQL .gz:

Gunzip <outputfile. SQL .gz | mysql <mysql options> Backup and bzip compression:

Mysqldump <mysqldump options> | bzip2> outputfile. SQL .bz2:

Bunzip2 <outputfile. SQL .bz2 | mysql <mysql options>


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 @#
Only selected records are exported. Note that the quotation marks are mandatory!
"-- Where = user =@# jimf @ #" "-wuserid> 1" "-wuserid <1"


MySQL Dump/Restore


Dump ALL MySQL Databases

The Code is as follows:
Mysqldump -- user = XXXXXXXX -- password = XXXXXXX-A>/PATH/TO/DUMPFILE. SQL

Dump Inpidual or Multiple MySQL Databases

The Code is as follows:
Mysqldump -- user = XXXXXXXX -- password = XXXXXXX -- databases DB_NAME1 DB_NAME2 DB_NAME3>/PATH/TO/DUMPFILE. SQL

Dump only certain tables from a MySQL Database

The Code is as follows:
Mysqldump -- user = XXXXXXXX -- password = XXXXXXXX -- databases DB_NAME -- tables TABLE_NAME>/PATH/TO/DUMPFILE. SQL

I'm using MySQL 4.1.8 on my development server, but am behind a few releases on our production server. in order to make dum compatible with the old MySQL version, add the following switch: -- compatible = mysql323
--------------------------------------------------------------------------------
Use the following procedure to reload the contents of a database:
Unzip the backup file you wish to use.
Open it up and pull out only the information that you will need.
Save this text file.
Use the following command to feed back in the contents of a text file:

The Code is as follows:
Mysql -- verbose -- user = XXXXXXXX -- password = XXXXXXXX DB_NAME </PATH/TO/DUMPFILE. SQL


Restoring MySQL database.
The mysqldump utility is used only to take the MySQL dump. To restore the database from the dump file that you created in previous step, use mysql command.

The Code is as follows:

Shell> mysql -- u [username] -- password = [password] [database name] <[dump file]

Example:

The Code is as follows:


Shell> mysql -- user root -- password = myrootpassword new_db <db_test. SQL

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.