1. 程式人生 > >mysqldump 參數

mysqldump 參數

--delete ise read oot sca lsp named any 設置變量

mysqldump是mysql用於轉存儲數據庫的實用程序。它主要產生一個SQL腳本,其中包含從頭重新創建數據庫所必需的命令CREATE TABLE INSERT等。對於導出的文件,可使用SOURCE命令導入數據庫。

使用mysqldump -?命令,可以查看mysqldump的具體參數及詳細說明。下表是一些常見的選項:

-A, --all-databases Dump all the databases. This will be same as --databases with all databases selected. 導出全部數據庫
-Y, --all-tablespaces Dump all the tablespaces. 導出全部表空間
-y, --no-tablespaces Do not dump any tablespace information. 不導出任何表空間信息
--add-drop-database Add a ‘DROP DATABASE‘ before each create. 每個數據庫創建之前添加drop數據庫語句
--add-drop-table Add a ‘drop table‘ before each create. 每個數據表創建之前添加drop數據表語句。(默認為打開狀態,使用--skip-add-drop-table取消選項)
--add-locks Add locks around insert statements. 在每個表導出之前增加LOCK TABLES並且之後UNLOCK TABLE。(默認為打開狀態,使用--skip-add-locks取消選項)
--allow-keywords Allow creation of column names that are keywords. 允許創建是關鍵詞的列名字。
--character-sets-dir=name Directory where character sets are. 字符集文件的目錄
-i, --comments Write additional information. 附加註釋信息。默認為打開,可以用--skip-comments取消
--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_options、no_tables_options、no_field_options等。要使用幾個值,用逗號將它們隔開。它並不保證能完全兼容,而是盡量兼容。
--compact Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks 導出更少的輸出信息(用於調試)。去掉註釋和頭尾等結構。可以使用選項:--skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys
-c, --complete-insert Use complete insert statements. 使用完整的insert語句(包含列名稱)。這麽做能提高插入效率,但是可能會受到max_allowed_packet參數的影響而導致插入失敗。
-C, --compress Use compression in server/client protocol. 在客戶端和服務器之間啟用壓縮傳遞所有信息
--create-options Include all MySQL specific create options. 在CREATE TABLE語句中包括所有MySQL特性選項。(默認為打開狀態)
-B, --databases To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. ‘USE db_name;‘ will be included in the output. 導出數據庫。參數後面所有名字參量都被看作數據庫名。
-#, --debug[=#] This is a non-debug version. Catch this and exit 輸出debug信息,用於調試。
--debug-check Check memory and open file usage at exit. 檢查內存和打開文件使用說明並退出。
--debug-info Print some debug info at exit. 輸出調試信息並退出
--default-character-set=name Set the default character set. 設置默認字符集
--delayed-insert Insert rows with INSERT DELAYED; 采用延時插入方式(INSERT DELAYED)導出數據
--delete-master-logs Delete logs on master after backup. This automatically enables --master-data. master備份後刪除日誌. 這個參數將自動激活--master-data。
-K, --disable-keys ‘/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and ‘/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output. 對於每個表,用/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;和/*!40000 ALTER TABLE tbl_name ENABLE KEYS */;語句引用INSERT語句。這樣可以更快地導入dump出來的文件,因為它是在插入所有行後創建索引的。該選項只適合MyISAM表,默認為打開狀態。
-E, --events Dump events. 導出事件。
-e, --extended-insert Allows utilization of the new, much faster INSERT syntax. 使用具有多個VALUES列的INSERT語法。這樣使導出文件更小,並加速導入時的速度。默認為打開狀態,使用--skip-extended-insert取消選項。
--fields-terminated-by=name Fields in the textfile are terminated by ... 導出文件中忽略給定字段。與--tab選項一起使用,不能用於--databases和--all-databases選項
--fields-enclosed-by=name Fields in the importfile are enclosed by ... 輸出文件中的各個字段用給定字符包裹。與--tab選項一起使用,不能用於--databases和--all-databases選項
--fields-optionally-enclosed-by=name Fields in the i.file are opt. enclosed by ... 輸出文件中的各個字段用給定字符選擇性包裹。與--tab選項一起使用,不能用於--databases和--all-databases選項
--fields-escaped-by=name Fields in the i.file are escaped by ... 輸出文件中的各個字段忽略給定字符。與--tab選項一起使用,不能用於--databases和--all-databases選項
-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 開始導出之前刷新日誌。
--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. 在導出mysql數據庫之後,發出一條FLUSH PRIVILEGES 語句。為了正確恢復,該選項應該用於導出mysql數據庫和依賴mysql數據庫數據的任何時候。
-f, --force Continue even if we get an sql-error. 在導出過程中忽略出現的SQL錯誤。
-?, --help Display this help message and exit. 顯示幫助信息並退出。
--hex-blob Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format. 使用十六進制格式導出二進制字符串字段。如果有二進制數據就必須使用該選項。影響到的字段類型有BINARY、VARBINARY、BLOB。
-h, --host=name Connect to host. 需要導出的主機信息
--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 ……
--insert-ignore Insert rows with INSERT IGNORE. 在插入行時使用INSERT IGNORE語句.
--lines-terminated-by=name Lines in the i.file are terminated by ... 輸出文件的每行用給定字符串劃分。與--tab選項一起使用,不能用於--databases和--all-databases選項。
-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 選項。
-l, --lock-tables Lock all tables for read. 開始導出前,鎖定所有表。用READ LOCAL鎖定表以允許MyISAM表並行插入。對於支持事務的表例如InnoDB和BDB,--single-transaction是一個更好的選擇,因為它根本不需要鎖定表。
請註意當導出多個數據庫時,--lock-tables分別為每個數據庫鎖定表。因此,該選項不能保證導出文件中的表在數據庫之間的邏輯一致性。不同數據庫表的導出狀態可以完全不同。
--log-error=name Append warnings and errors to given file. 附加警告和錯誤信息到給定文件
--no-autocommit Wrap tables with autocommit/commit statements. 使用autocommit/commit 語句包裹表
-n, --no-create-db ‘CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;‘ will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}. 只導出數據,而不添加CREATE DATABASE 語句
-t, --no-create-info Don‘t write table creation info. 只導出數據,而不添加CREATE TABLE 語句
-d, --no-data No row information. 不導出任何數據,只導出數據庫表結構
--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. 等同於--add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, --disable-keys 該選項默認開啟, 可以用--skip-opt禁用.
--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. 如果存在主鍵,或者第一個唯一鍵,對每個表的記錄進行排序。在導出MyISAM表到InnoDB表時有效,但會使得導出工作花費很長時間。
-p, --password[=name] Password to use when connecting to server. If password is not given it‘s solicited on the tty. 連接數據庫密碼
-W, --pipe Use named pipes to connect to server. 使用命名管道連接mysql(windows系統可用)
-P, --port=# Port number to use for connection. 連接數據庫端口號
--protocol=name The protocol of connection (tcp,socket,pipe,memory). 使用的連接協議,包括:tcp, socket, pipe, memory.
-q, --quick Don‘t buffer query, dump directly to stdout. 不緩沖查詢,直接導出到標準輸出。默認為打開狀態,使用--skip-quick取消該選項。
-Q, --quote-names Quote table and column names with backticks (`). 使用(`)引起表和列名。默認為打開狀態,使用--skip-quote-names取消該選項。
--replace Use REPLACE INTO instead of INSERT INTO. 使用REPLACE INTO 取代INSERT INTO.
-r, --result-file=name Direct output to a given file. This option should be used in MSDOS, because it prevents new line ‘\n‘ from being converted to ‘\r\n‘ (carriage return + line feed). 直接輸出到指定文件中。該選項應該用在使用回車換行對(\\r\\n)換行的系統上(例如:DOS,Windows)。該選項確保只有一行被使用。
-R, --routines Dump stored routines (functions and procedures). 導出存儲過程以及自定義函數。
--set-charset Add ‘SET NAMES default_character_set‘ to the output. Enabled by default; suppress with --skip-set-charset. 添加‘SET NAMES default_character_set‘到輸出文件。默認為打開狀態,使用--skip-set-charset關閉選項。
-O, --set-variable=name Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value. 設置變量的值
--dump-date Put a dump date to the end of the output. 添加DUMP時間到輸出末尾
--skip-opt Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. 禁用–opt選項.
-S, --socket=name Socket file to use for connection. 指定連接mysql的socket文件位置,默認路徑/tmp/mysql.sock
-T, --tab=name Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon. 為每個表在給定路徑創建tab分割的文本文件。註意:僅僅用於mysqldump和mysqld服務器運行在相同機器上。
--tables Overrides option --databases (-B). 覆蓋--databases (-B)參數,指定需要導出的表名。
--triggers Dump triggers for each dumped table 導出觸發器。該選項默認啟用,用--skip-triggers禁用它。
--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. 在導出頂部設置時區TIME_ZONE=‘+00:00‘ ,以保證在不同時區導出的TIMESTAMP 數據或者數據被移動其他時區時的正確性。
-u, --user=name User for login if not current user. 指定連接的用戶名。
-v, --verbose Print info about the various stages. 輸出多種平臺信息。
-V, --version Output version information and exit. 輸出mysqldump版本信息並退出
-w, --where=name Dump only selected records; QUOTES mandatory! 只轉儲給定的WHERE條件選擇的記錄。請註意如果條件包含命令解釋符專用空格或字符,一定要將條件引用起來。
-X, --xml Dump a database as well formed XML. 導出XML格式.

示例:
1、導出數據庫下某個表的結構
C:\Users\qxl>mysqldump -uroot -p -d mydb t_user
2、按條件只導出表中的數據
C:\Users\qxl>mysqldump -uroot -p "--where=id<10" -t mydb t_user

mysqldump 參數