mysqldump命令參數
mysql?
mysqldump客戶端可用來轉儲數據庫或搜集數據庫進行備份或將數據轉移到另一個SQL服務器(不一定是一個MySQL服務器)。轉儲包含創建表和/或裝載表的SQL語句。?
如果你在服務器上進行備份,并且表均為MyISAM表,應考慮使用mysqlhotcopy,因為可以更快地進行備份和恢復。?
有3種方式來調用mysqldump:
shell> mysqldump [options] db_name [tables] shell> mysqldump [options] ---database DB1 [DB2 DB3...] shell> mysqldump [options] --all--database
如果沒有指定任何表或使用了---database或--all--database選項,則轉儲整個數據庫。?
要想獲得你的版本的mysqldump支持的選項,執行mysqldump ---help。?
如果運行mysqldump沒有--quick或--opt選項,mysqldump在轉儲結果前將整個結果集裝入內存。如果轉儲大數據庫可能會出現問題。該選項默認啟用,但可以用–skip-opt禁用。?
如果使用最新版本的mysqldump程序生成一個轉儲重裝到很舊版本的MySQL服務器中,不應使用–opt或-e選項。
mysqldump支持下面的選項:
1、--print-defaults Print the program argument list and exit.
打印程序參數列表并退出
2、--no-defaults Don't read default options from any option file
已不從任何選項文件讀取默認選項
3、--defaults-file=# Only read default options from the given file #.
只有給指定的文件讀取默認選項
4、--defaults-extra-file=# Read this file after the global files are read.
在全局下面讀取這個文件
5、-A, --all-databases Dump all the databases. This will be same as --databases
所有的數據庫
6、-Y, --all-tablespaces Dump all the tablespaces.
導出全部表空間
7、-y, --no-tablespaces Do not dump any tablespace information.
不導出任何表空間
8、--add-drop-database Add a DROP DATABASE before each create.
每個數據庫創建之前添加drop數據庫語句
9、--add-drop-table Add a DROP TABLE before each create.
每個數據表創建之前添加drop數據表語句。(默認為打開狀態,使用–sjip-add-drop-table取消選項)(Defaults to on; use --skip-add-drop-table to disable.)
10、--add-locks Add locks around INSERT statements.(Defaults to on; use --skip-add-locks to disable.)
在每個表導出之前增加LOCK TABLES并且之后UNLOCK TABLE(為了使得更快地插入到MySQL)。默認開啟。
11、--allow-keywords Allow creation of column names that are keywords.
允許創建是關鍵詞的列明子。這由表名前綴每個列名做到
12、 --apply-slave-statements Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump
在CHANGE MASTER前添加STOP SLAVE,并且在導出的最后添加START SLAVE.
13、--character-sets-dir=name Directory for character set files.
字符集文件的目錄
14、-i, --comments Write additional information.
15、--compatible=name Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. This option is ignored with earlier server versions.
導出數據將和其他數據庫和舊版本的MySQL 相兼容.值可以為ansi、mysql323、mysql40、postgresql、oracle、mssql、db2、maxdb、no_key_opt、no_tables_options、no_field?
例子:
mysqldump -uroot -p --all-databases --compatible=ansi
16、 --compact Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys --skip-set-charset.
導出更少的輸出信息(用于調試)去掉注釋和頭尾等結構。可以使用選項:
--skip-add-drop-table --skip-add-locks--skip-comments --skip-disable-key
例子:mysqldump -uroot -p --all-databases --compact
17、 -c, --complete-insert Use complete insert statements
使用完成的insert語句(包含列名稱),這么做能提高插入效率,但是可能會受到max_allowed_packer參數的影響而導致插入失敗?
例子:mysqldump -uroot -p --all-databases --complete-insert
18、 -C, --compress Use compression in server/client protocol.
在客戶端和服務器之間啟用壓縮傳遞所有信息?
例子:mysqldump -uroot -p --all-databases --compress
19、-a, --create-options Include all MySQL specific create options. (Defaults to on; use --skip-create-options to disable.)
在CREATE TABLE語句中包括所有MySQL特性選項。(默認為打開狀態)?
例子:mysqldump -uroot -p --add-databases
20、-B, --databases Dump several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names. 'USE db_name;' will be included in the output.
導出數據里面添加創建數據庫的語句和切入數據庫
21、-#, --debug[=#] This is a non-debug version. Catch this and exit.
輸出debug信息,用于調試。默認值為d:t:o,/tmp/mysqldump.trace?
例子:
mysqldump —uroot -p --add-databases --debugmysqldump -uroot -p --add-databases --debug="d:t:o,/tmp/debug.trace"
————-分割線————
22、--debug-check Check memory and open file usage at exit.
檢查內存和打開文件使用說明并退出?
例子:mysqldump -uroot -p --add-databases --debug-check
23、--debug-info Print some debug info at exit.
輸出調試信息并推出?
例子:mysqldump -uroot -p --add-databases --debug-info
24、--default-character-set=name Set the default character set.
設置默認字符集,默認值為utf8?
mysqldump -uroot -p --add-databases --default-character-set=latin1
25、--delayed-insert Insert rows with INSERT DELAYED.例子:mysqldump -uroot -p --add-databases --delayed-insert
采用延時插入方式(INSERT DELAYED)導出數據
26、--delete-master-logs Delete logs on master after backup. This automatically enables --master-data.例子:mysqldump -uroot -p --add-databases --delete-master-logs
master備份后刪除日志,這個參數將自動激活--master-data
27、-K, --disable-keys '/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output. (Defaults to on; use --skip-disable-keys to disable.)例子:mysqldump -uroot -p --add-databases
對于每個表,用/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;?
和/*!40000 ALTER TABLE tbl_name ENABLE KEYS */;語句引用INSERT?語句。這樣可以更快地導出dump出來的文件,因為它是在插入所有行后創建索引.該選項只適合MyISAM表,默認為打開狀態.
28、--dump-slave[=#] This causes the binary log position and filename of the master to be appended to the dumped data output. Setting the value to 1, will printit as a CHANGE MASTER command in the dumped data output; if equal to 2, that command will be prefixed with a comment symbol. This option will turn --lock-all-tables on, unless --single-transaction is specified too (in which case a global read lock is only taken a short time at the beginning of the dump - don't forget to read about --single-transaction below). In all cases any action on logs will happen at the exact moment of the dump.Option automatically turns --lock-tables off. ------------------例子:mysqldump -uroot -p --add-databases --dump-slave=1 mysqldump -uroot -p --all-databases --dump-slave=2
該選項導致主的binlog位置和文件名追加到導出數據的文件中。設置為1時,將會以CHANGE MASTER命令輸出到數據文件;?
設置為2時,在命令前增加說話信息。該選項將會打開--lock-all-tables,除非--single-transaction被指定。該選項會自動關閉–lock-tables選項。默認值為0
29、-E, --events Dump events.例子:mysqldump -uroot -p --add-databases --events
導出事件
30、-e, --extended-insert Use multiple-row INSERT syntax that include several VALUES lists. (Defaults to on; use --skip-extended-insert to disable.)例子:mysqldump -uroot -p --all-databases mysqldump -uroot -p --all-databases --skip-extended-insert(取消選項)
使用具有多個VALUES列的INSERT語句.并加速導入時的速度。默認為打開狀態,使用--skip-extended-insert取消選項。
31、--fields-terminated-by=name Fields in the output file are terminated by the given string.例子:mysqldump -uroot -p test test --tab="/home/mysql" --fields-terminated-by="#"
導出文件中忽略給定字段。與--tab選項一起使用,不能用于--databases和--all-databases選項
32、--fields-enclosed-by=name Fields in the output file are enclosed by the given character.例子:mysqldump -uroot -p test test --tab="/home/mysql" --fields-enclosed-by="#"
輸出文件中的各個字段用給定字符包括。與--tab選項一起使用,不能用于--databases和--all-databases選項
33、--fields-optionally-enclosed-by=name Fields in the output file are optionally enclosed by the given character.例子:mysqldump -uroot -p test test --tab="/home/mysql"--fields-enclosed-by="#" --fields-optionally-enclosed-by ="#"
輸出文件中的各個字段用給定字符選項性包括。與--tab選項一起使用,不能用于--databases和--all-databases選項
34、--fields-escaped-by=name Fields in the output file are escaped by the given character.例子:mysqldump -uroot -p mysql user --tab="/home/mysql" --fields-escaped-by="#"
輸出文件中的各個字段忽略給定字符.與–tab選項一起使用,不能用于--databases和--all-databases選項
35、-F, --flush-logs Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables or --master-data: in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --master-data with --flush-logs.例子:mysqldump -uroot -p --add-databases --flush-privileges
開始導出之前刷新日志?
請注意:加入一次導出多個數據庫(使用選項--databases或者--all-databases)將會逐個數據庫刷新日志.除使用--lock-all-tables或者--master-data外。在這種情況下,日志將會被刷新一次,相應的所有表同時被鎖定。因此,如果打算同時導出和刷新日志應該使用--lock-all-tables或者--master-data和--flush-logs
36、--flush-privileges Emit a FLUSH PRIVILEGES statement after dumping the mysql database. This option should be used any time the dump contains the mysql database and any other database that depends on the data in the mysql database for proper restore.例子:mysqldump -uroot -p --all-databases --flush-privilege
在導出mysql數據庫之后,發出一條FLUSH PRIVILEGES語句.為了正確恢復,該選項應該用于導出mysql數據庫和依賴mysql數據庫數據的任何時候。
37、-f, --force Continue even if we get an SQL error.例子:mysqldump -uroot -p --add-databases --force
在導出過程中忽略出現的SQL錯誤
38、-?, --help Display this help message and exit.例子:mysqldump --help
顯示幫助信息并退出
39、--hex-blob Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format.例子:mysqldump -uroot -p --all-databases --hex-blob
使用十六進制格式導出二進制字符串字段。如果有二進制數據就必須使用該選項。影響到的字段類型有BINARY、VARBINARY、BLOB.
40、-h, --host=name Connect to host.例子:mysqldump -uroot -p host=localhost --all-databases
需要導出的主機信息
41、--ignore-table=name Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. Each table must be specified with both database and table names, e.g., --ignore-table=database.table.例如: --ignore-table=database.table1 --ignore-table=database.table2.....例子:mysqldump -uroot -p --host=localhost --all-databases --ignore-tanle=mysql.user
不導出指定表,指定忽略多個表時,需要重復多次。每次一個表,每個表必須同時指定數據庫和表名
42、 --include-master-host-port Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.
在--dump-slave產生的CHANGE MASTER TO ....語句中增加'MASTER_HOST=<host>,MASTER_PROT=<prot>'?
mysqldump -uroot -p –host=localhost –all-databases –include-master-host-port
43、--insert-ignore Insert rows with INSERT IGNORE.例子:mysqldump -uroot -p --host=localhost --all-databases --insert-ignore
在插入行使用INSERT IGNORE語句
44、--lines-terminated-by=name Lines in the output file are terminated by the given string.------例子:mysqldump -uroot -p --host=localhost test test --tab="/tmp/mysql" --lines-terminated-by="##"
輸出文件的每行用定字符串劃分.與--tab選項一起使用,不能用于--database和--all-databases選項。
45、-x, --lock-all-tables Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction and --lock-tables off.
提交請求鎖定所有數據庫中的所有表,以保證數據的一致性。這是一個全局讀鎖,并且自動關閉--single-transaction和--lock-tables選項
46、-l, --lock-tables Lock all tables for read. (Defaults to on; use --skip-lock-tables to disable.)-----------mysqldump -uroot -p --host=localhost --all-databases --lock-tables
開始導出前,多訂所有表。用READ LOCAL鎖定表以允許MyISAM表并行插入.對于支持事務的表例如InnoDB和BDB,--single-transaction是一個更好的選擇,因為它根本不需要鎖定表。?
請注意當導出多個數據庫時,--lock-tables分別為每個數據庫鎖定表。因此,該選項不能保證導出文件的表在數據庫之間的邏輯一致性。不同數據庫表的導出狀態完全不同。
47、--log-error=name Append warnings and errors to given file.-------------例子:mysqldump -uroot -p --host=localhost --add-databases --log-error=/tmp/err_log
附加警告和錯誤信息到給定文件
48、--master-data[=#] This causes the binary log position and filename to be appended to the output. If equal to 1, will print it as a CHANGE MASTER command; if equal to 2, that command will be prefixed with a comment symbol. This option will turn --lock-all-tables on, unless --single-transaction is specified too (in which case a global read lock is only taken a short time at the beginning of the dump; don't forget to read about --single-transaction below). In all cases, any action on logs will happen at the exact moment of the dump. Option automatically turns --lock-tables off.
該選項將binlog的位置和文件名追加到輸出文件中。如果為1,將會輸出CHANGE MASTER命令;如果為2,輸出的CHANGE MASTER命令前添加注釋信息。該選項打開--lock-all-tables?選項,除非--single-transaction也被鎖定。?
(在這種情況下,全局讀鎖在開始導出時獲得很短的時間;其他內容參考下面的--single-transaction選項)。該選項自動關閉--lock-tables
例子:mysqldump -uroot -p --host=localhost --all-databases --master-data=1; mysqldump -uroot -p --host=localhost --all-databases --master-data=2;
——————分割線————–
49、--max-allowed-packet=# The maximum packet length to send to or receive from server.例子:mysqldump -uroot-p --host=localhost --all-database --max_allowed_packer=100240
服務器發送和接受的最大包長度。
50、--net-buffer-length=# The buffer size for TCP/IP and socket communication.例子:mysqldump -uroot -p --host=localhost --all-databases --net_buffer_length=10024
TCP/IP和socket連接的緩存大小
51、--no-autocommit Wrap tables with autocommit/commit statements.例子:mysqldump -uroot -p --host=localhost --all-databases --no-autocommit
使用autocommit/commit語句包裹表。
52、-n, --no-create-db Suppress the CREATE DATABASE ... IF EXISTS statement that normally is output for each dumped database if --all-databases or --databases is given.例子:mysqldump -uroot -p --host=localhost --all-databases --no-create-db
只導出數據,而不添加CREATE DATABASE語句
53、-t, --no-create-info Don't write table creation info.例子:mysqldump -uroot -p --host=localhost --all-databases --no-create-info
只導出數據,而不添加CREATE TABLE?語句
54、-d, --no-data No row information.例子:mysqldump -uroot -p --host=localhost --all-databases --no-data
只導出數據,而不添加CREATE TABLE語句
55、-N, --no-set-names Same as --skip-set-charset.例子:mysqldump -uroot -p --host=localhost --all-databases --no-set-names
等同于--skip-set-charset
56、--opt Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.--------例子:mysqldump -uroot -p --host=localhost --all-databases --opt
等同于--add-drop-table,--add-locks,--create-options,--quick,--extended-insert,--lock-tables,--set-charset,--disable-keys?該選項默認開啟,可以用--skip-opt禁用
57、--order-by-primary Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.例子:mysqldump -uroot -p --host=localhost --all-database --order-by-primary
如果存在主鍵,或者第一個唯一鍵,對每個表的記錄進行排序。在導出MyISAM表到InnoDB表時有效,但會使得導出工作花費很長時間。
58、-p, --password[=name] Password to use when connecting to server. If password is not given it's solicited on the tty.
連接數據庫密碼
59、-P, --port=# Port number to use for connection.
連接數據庫端口號
60、--protocol=name The protocol to use for connection (tcp, socket, pipe, memory).例子:mysqldump -uroot -p --host=localhost --all-databases --protocol=tcp
使用的連接協議,包括:tcp、socker、pipe、memory
61、-q, --quick Don't buffer query, dump directly to stdout. (Defaults to on; use --skip-quick to disable.) ------例子:mysqldump -uroot -p --host=localhost --all-database mysqldump -uroot -p --host=localhost --all-database --skip-quick
不緩沖查詢,直接導出到標準輸出。默認為打開狀態,使用--skip-quick取消該選項。
62、-Q, --quote-names Quote table and column names with backticks (`). (Defaults to on; use --skip-quote-names to disable.)-------mysqldump -uroot -p --host=localhost --all-databasemysqldump -uroot -p --host=localhost --all-database --skip-quote-names
使用(`)引起表和列名。默認為打開狀態,使用--skip-quote-names取消該選項。
63、--replace Use REPLACE INTO instead of INSERT INTO.----------mysqldump -uroot -p --host=localhost --all-database --replace
使用REPLACE INTO?取代INSERT INTO.
64、-r, --result-file=name Direct output to a given file. This option should be used in systems (e.g., DOS, Windows) that use carriage-return linefeed pairs (\r\n) to separate text lines. This option ensures that only a single newline is used.----------------mysqldump -uroot -p --host=localhost --all-databases --result-file=/tmp/mysqldump_result_file.txt
直接輸出到指定文件中。該選項應該用在使用回車換行對(\\r\\n)換行的系統上(例如:DOS,Windows)。該選項確保只有一行被使用
65、-R, --routines Dump stored routines (functions and procedures). ------mysqldump -uroot -p --host=localhost --all-databases --routines
導出存儲過程以及自定義函數。
66、--set-charset Add 'SET NAMES default_character_set' to the output. (Defaults to on; use --skip-set-charset to disable.)-----------------mysqldump -uroot -p --host=localhost --all-databasesmysqldump -uroot -p --host=localhost --all-database --skip-set-charset
添加'SET NAMES default_character_set'到輸出文件。默認為打開狀態,使用--skip-set-charset關閉選項。
67、--single-transaction Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log position), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables------------------mysqldump -uroot -p --host=localhost --all-database --single-transaction
改選項在導出數據之前提交一個BEGIN SQL語句,BEGIN不會阻塞任何應用程序且能保證導出時的數據庫的一致性狀態,他只使用與多版本存儲引擎,僅InnoDB?本選項和--lock-tables?選項是互相互斥的,因為LOCK TABLES?會使任何掛起的事務隱含提交。要想導出大表的話,應結合使用--quick選項。
68、 --dump-date Put a dump date to the end of the output. (Defaults to on; use --skip-dump-date to disable.)例子:mysqldump -uroot -p --host=localhost --all-database mysqldump -uroot -p --host=localhost --all-databases --skip-dump-date
將導出時間添加到輸出文件中。默認為打開狀態,使用--skip-dump-data關閉選項
69、 --skip-opt Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.---------------mysqldump -uroot -p --host=localhost --all-databases --skip-opt
禁用-opt選項
70、-S, --socket=name The socket file to use for connection.---------mysqldump -uroot -p --host=localhost --all-databases --skip-opt
指定連接mysql的socket文件位置,默認路徑/tmp/mysql.sock
71、 -T, --tab=name Create tab-separated textfile for each table to given path. (Create .sql and .txt files.) NOTE: This only works if mysqldump is run on the same machine as the mysqld server.mysqldump -uroot -p --host=localhost test test --tab="/home/mysql"
為每個表在給定路徑創建tab分隔的文本文件。注意:僅僅用于mysqldump和mysqld服務器運行在相同機器上,
72、--tables Overrides option --databases (-B).---------------mysqldump -uroot -p --host=localhost --database test --tables test
覆蓋--database?(-B)參數,需要導出的表名。
73、--triggers Dump triggers for each dumped table. (Defaults to on; use --skip-triggers to disable.)----------------mysqldump -uroot -p --host=localhost --all-database --trigger
導出發出器。該選項默認啟用,用--skip-trigger禁用它。
74、--tz-utc SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones. (Defaults to on; use --skip-tz-utc to disable.)--------------mysqldump -uroot -p --host=localhost --all-databases --tz-utc
在導出頂部設置時區TIME_ZONE='+00:00'?以保證不同時區導出的TIMESTAMP?數據或數據被移動其他時區時的正確性。
75、-u, --user=name User for login if not current user.
指定連接的用戶名
76、-v, --verbose Print info about the various stages.
輸出多種平臺信息
77、-V, --version Output version information and exit.
輸出mysqldump版本信息并退出
78、-w, --where=name Dump only selected records. Quotes are mandatory.-----------------mysqldump -uroot -p --host=localhost --all-databases --where="user='root'"
只轉儲給定的WHERE條件選擇的記錄。請注意如果條件包含命令解釋符專用空格或字符,一定要將條件引用起來
79、-X, --xml Dump a database as well formed XML.mysqldump -uroot -p --host=localhost --all-database --xml
導出XML格式
80、--plugin-dir=name Directory for client-side plugins.-------------------mysqldump -uroot -p --host=localhost --all-databases --plug_dir="/usr/local/lib/"
客戶端插件的目錄,用于兼容不同的插件版本
81、--default-auth=name Default authentication client-side plugin to use.---------------mysqldump -uroot -p --host=localhost --all-database --default-auth="/usr/local/lib/plugin/<PLUGIN>"
客戶端插件默認使用
82、--enable-cleartext-plugin Enable/disable the clear text authentication plugin.
啟用/禁用 明文的身份驗證插件
總結
以上是生活随笔為你收集整理的Mysqldump命令参数介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。