Learning MySQL - mysqldump command using the Backup and Restore
Abstract: This paper to learn how to use the mysqldump command to back up and restore the database.
export data
Export all data
parameter:
1 --all-databases, -A
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A > db_back.sql
Export specified database
parameter:
1 --databases, -B
For example:
1 mysqldump -h127.0.0.1 -uroot -p -B test mysql > db_back.sql
Export all table spaces
parameter:
1 --all-tablespaces, -Y
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A -Y > db_back.sql
Add and delete database statement before each database created
parameter:
1 --add-drop-database
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --add-drop-database > db_back.sql
Add to delete actions immediately before each table create table
The default open state, using --skip-add-drop-table parameters canceled.
parameter:
. 1 --add-drop-Table // add puncturing table operation. 2 --skip the Add-drop-Table- // cancel the delete operation table.
For example:
. 1 the mysqldump -h127.0.0.1 -uroot--A -p> db_back.sql // default to the puncturing table operation. 2 the mysqldump -h127.0.0.1 -uroot--p -A---skip the Add-drop-Table> db_back.sql // cancel the delete operation table.
Lock table in front of each table is exported and after exporting unlocked
Is on by default, use --skip-add-locks parameter canceled.
parameter:
1 --add-Locks // add table lock and unlock operations. 2 --skip-the Add-Locks // cancel the lock and unlock operations table.
For example:
. 1 the mysqldump -h127.0.0.1 -uroot--A -p> db_back.sql // default to the lock table and unlocking operations. 2 the mysqldump -h127.0.0.1 -uroot--p -A---skip the Add-Locks> db_back.sql // cancel the lock table and unlocking operations.
Ignore the specified table
Do not export the specified table. When you specify more than one table to ignore, need to be repeated several times, each time a table, each table must specify the database and table name at the same time.
parameter:
1 --ignore-table
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --ignore-table=database.table1 --ignore-table=database.table2 > db_back.sql
Exporting data is not only added to create the database
parameter:
1 --no-create-db, -n
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --no-create-db > db_back.sql
Exporting data does not only add to create a data table
parameter:
1 --no-create-info, -t
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --no-create-info > db_back.sql
Not only export data export structure
parameter:
1 --no-data, -d
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --no-data > db_back.sql
Exporting stored procedures and custom functions
parameter:
1 --routines, -R
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --routines > db_back.sql
Set the character set files directory
The default is utf8.
parameter:
1 --default-character-set
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --default-character-set=latin1 > db_back.sql
Set the character set files directory
parameter:
1 --character-sets-dir
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --character-sets-dir=/data/mysql/share/charsets > db_back.sql
Between the client and server to pass all the information to enable compression
parameter:
1 --compress, -C
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A -C > db_back.sql
Port number of the database
parameter:
1 --port, -P
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --port=3306 > db_back.sql
Use of connection agreements
parameter:
1 --protocol
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --protocol=tcp > db_back.sql
Wrap treatment
Direct output to the specified file. This option should be used on systems that use line breaks to (\\ r \\ n) line feed (for example: DOS, Windows). This option ensures that only one line is used.
parameter:
1 --result-file, -r
For example:
1 mysqldump -h127.0.0.1 -uroot -p -A --result-file=/tmp/mysqldump_result_file.txt > db_back.sql
Add Export Time
Export the time added to the output file. It is on by default, use --skip-dump- DATE parameter canceled.
parameter:
1 --dump- DATE // export time added to the output file. 2 --skip-dump- DATE // not export the time added to the output file.
For example:
. 1 the mysqldump -h127. 0.0 . . 1 -uroot--p -A // default time export added to the output file. 2 the mysqldump -h127. 0.0 . . 1 -uroot--p -A-dump- --skip DATE // not export time added to the output file.