来自http://tunps.com/mysqldump-help
mysqldump Ver 10.13 Distrib 5.1.50, for Win32 (ia32)
By Igor Romanenko, Monty, Jani & Sinisa.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license.
Dumping structure and contents of MySQL databases and tables.
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
Default options are read from the following files in the given order:
C:\WINDOWS\my.ini C:\WINDOWS\my.cnf C:\my.ini C:\my.cnf D:\pn\MySQL-5.1.50\my.ini D:\pn\MySQL-5.1.50\my.cnf
The following groups are read: mysqldump client
默认需要读取配置文件的路径
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
打印程序参数列表,参数列表来自mysql配置文件的[mysqldump]节点
--no-defaults Don't read default options from any option file.
不读取mysql配置文件[mysqldump]节点下的选项
--defaults-file=# Only read default options from the given file #.
只是从指定配置文件读取选项
--defaults-extra-file=# Read this file after the global files are read.
读取defaults-file指定的文件,然后读取extra文件
--all Deprecated. Use --create-options instead.
过时选项,使用--create-options代替
-A, --all-databases Dump all the databases. This will be same as --databases
with all databases selected.
导出所有的数据库,和--databases参数一样
-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.
在每个create database语句前添加“DROP DATABASE”语句
--add-drop-table Add a DROP TABLE before each create.
在每一个表的前面加上“DROP TABLE IF EXISTS”语句,
这样可以保证IMPORT您的MySQL数据库的时候不会出错,
因为每次导回的时候,都会首先检查表是否存在,存在就删除
--add-locks Add locks around INSERT statements.
这个选项会在INSERT语句中捆上一个LOCK TABLE和UNLOCK TABLE语句。
这就防止在这些记录被再次导入数据库时其他用户对表进行的操作
比如:
LOCK TABLES `pwss` WRITE;
/*!40000 ALTER TABLE `pwss` DISABLE KEYS */;
INSERT INTO `pwss` VALUES (1,'weiwei','I love this girl');
/*!40000 ALTER TABLE `pwss` ENABLE KEYS */;
UNLOCK TABLES;
--allow-keywords Allow creation of column names that are keywords.
允许创建关键字字段
--character-sets-dir=name
Directory for character set files.
指定存放字符集文件的所在目录
-i, --comments Write additional information.
给这次备份写个备注
--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_table_options,no_field_options。可以用逗号隔开同时使用多个模式
这个选项需要4.1.0版本以上的支持。更老的版本会自动忽略这个选项。
--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.
输出更少的备注,禁止表结构备注,dump文件的头和维的备注。
-c, --complete-insert
Use complete insert statements.
这个选项使得mysqldump命令给每一个产生INSERT语句加上列(field)的名字。
当把数据导出导另外一个数据库时这个选项很有用。
比如:INSERT INTO `pwss` (`id`, `username`, `description`) VALUES (1,'weiwei','I love this girl');
-C, --compress Use compression in server/client protocol.
传输使用压缩
-a, --create-options
Include all MySQL specific create options.
包含所有的mysql创建选项
-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.
导出指定数据库,参数都是数据库名,'USE db_name;'会写入导出文件中
-#, --debug[=#] This is a non-debug version. Catch this and exit.
非调试版
--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,可以将读取到的INSERT语句还没有来得及执行的先放入缓存中,有空闲时间再执行INSERT。
--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 tb_name DISABLE KEYS */;
'/*!40000 ALTER TABLE tb_name ENABLE KEYS */;
-E, --events Dump events.
导出事件
-e, --extended-insert
Use multiple-row INSERT syntax that include several
VALUES lists.
使用多行插入的INSERT语法
--fields-terminated-by=name
Fields in the output file are terminated by the given
string.
--fields-enclosed-by=name
Fields in the output file are enclosed by the given
character.
--fields-optionally-enclosed-by=name
Fields in the output file are optionally enclosed by the
given character.
--fields-escaped-by=name
Fields in the output file are escaped by the given
character.
这些选择与-T(--tab)选择一起使用,并且有相应的LOAD DATA INFILE子句相同的含义。
--first-slave Deprecated, renamed to --lock-all-tables.
-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.
在执行导出之前将会刷新MySQL服务器的log.
--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.
-f, --force Continue even if we get an SQL error.
即使有错误发生,仍然继续导出
-?, --help Display this help message and exit.
显示此mysqldump的帮助
--hex-blob Dump binary strings (BINARY, VARBINARY, BLOB) in
hexadecimal format.
-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.table.今天碰到了这个参数的实际应用:mysqldump --database --ignore-table=db1.tbl db1 >backup_db1_2011.4.7.sql
--insert-ignore Insert rows with INSERT IGNORE.
--lines-terminated-by=name
Lines in the output file are terminated by the given
string.
-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.
-l, --lock-tables Lock all tables for read.
给表读取加锁
--log-error=name Append warnings and errors to given file.
--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.
--max_allowed_packet=#
The maximum packet length to send to or receive from
server.
--net_buffer_length=#
The buffer size for TCP/IP and socket communication.
--no-autocommit Wrap tables with autocommit/commit statements.
-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.
-t, --no-create-info
Don't write table creation info.
只是用“CREATE TABLE”的数据,而导出用表结构
-d, --no-data No row information.
和--no-create-info相反,只导出表结构,不导出数据
-N, --no-set-names Suppress the SET NAMES statement
--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,
and --disable-keys的组合,此选项将打开所有会提高文件导出速度和创造一个可以更快导入的文件的选项。
如果没有使用--opt,MYSQLDUMP就会把整个结果集装载到内存中,然后导出。
如果数据非常大就会导致导出失败。这个开关在默认情况下是启用的,如果不想启用它:--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.
-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.
-P, --port=# Port number to use for connection.
指定连接端口
--protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
指定连接协议(可以是tcp,socket,pipe,memory)
-q, --quick Don't buffer query, dump directly to stdout.
这个选项使得MySQL不会把整个导出的内容读入内存再执行导出,
而是在读到的时候就写入导文件中。这个和上面的开关一个意思。
-Q, --quote-names Quote table and column names with backticks (`).
--replace Use REPLACE INTO instead of 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, --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.
过时的选项,可以通过--variable-name来设定变量
--shared-memory-base-name=name
Base name of shared memory.
--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.
--dump-date Put a dump date to the end of the output.
--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 The socket file to use for connection.
与localhost连接时(它是缺省主机)使用的套接字文件。 (用于linux系统)
--ssl Enable SSL for connection (automatically enabled with
other flags).Disable with --skip-ssl.
--ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
--ssl).
--ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=name X509 cert in PEM format (implies --ssl).
--ssl-cipher=name SSL cipher to use (implies --ssl).
--ssl-key=name X509 key in PEM format (implies --ssl).
--ssl-verify-server-cert
Verify server's "Common Name" in its cert against
hostname used when connecting. This option is disabled by
default.
-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.
这个选项将会创建两个文件,一个文件包含DDL语句或者表创建语句,另一个文件包含数据。
DDL文件被命名为tableName.sql,数据文件被命名为tableName.txt.路径名是存放这两个文件的目录。
目录必须已经存在,并且命令的使用者有对文件的特权。
(tableName.txt的结果相当于用select * from tablename into outfile的生成数据)
比如:mysqldump -uroot -px tun1 tb1 -c --tab="c:\\"
--tables Overrides option --databases (-B).
覆盖--databases选项
--triggers Dump triggers for each dumped table.
导出触发器
--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.
可以通过--tz-utc调整时区,完成不同时区的服务器的迁移
-u, --user=name User for login if not current user.
登录用户
-v, --verbose Print info about the various stages.
导出时输出当前行为:
-- Connecting to localhost...
-- Retrieving table structure for table tb1...
-- Sending SELECT query...
-- Retrieving rows...
-- Disconnecting from localhost...
-V, --version Output version information and exit.
输出mysqldump的版本信息:比如:mysqldump Ver 10.13 Distrib 5.1.50, for Win32 (ia32)
-w, --where=name Dump only selected records. Quotes are mandatory.
使用where限定条件,条件语句必须使用引号 比如:--where="id=1" 或者 -w="id=1"
-X, --xml Dump a database as well formed XML.
到处成一个格式化好的xml文件
以下是默认的变量:
Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- -----------------------------
all TRUE
all-databases FALSE
all-tablespaces FALSE
no-tablespaces FALSE
add-drop-database FALSE
add-drop-table TRUE
add-locks TRUE
allow-keywords FALSE
character-sets-dir (No default value)
comments TRUE
compatible (No default value)
compact FALSE
complete-insert FALSE
compress FALSE
create-options TRUE
databases FALSE
debug-check FALSE
debug-info FALSE
default-character-set utf8
delayed-insert FALSE
delete-master-logs FALSE
disable-keys TRUE
events FALSE
extended-insert TRU
fields-terminated-by (No default value)
fields-enclosed-by (No default value)
fields-optionally-enclosed-by (No default value)
fields-escaped-by (No default value)
first-slave FALSE
flush-logs FALSE
flush-privileges FALSE
force FALSE
hex-blob FALSE
host (No default value)
insert-ignore FALSE
lines-terminated-by (No default value)
lock-all-tables FALSE
lock-tables TRUE
log-error (No default value)
master-data 0
max_allowed_packet 16777216 //最大包大小:16MB
net_buffer_length 1046528 //缓冲区大小:1MB
no-autocommit FALSE
no-create-db FALSE
no-create-info FALSE
no-data FALSE
order-by-primary FALSE
port 3306 //默认端口
quick TRUE
quote-names TRUE
replace FALSE
routines FALSE
set-charset TRUE
shared-memory-base-name (No default value)
single-transaction FALSE
dump-date TRUE
socket /tmp/mysql.sock
ssl FALSE
ssl-ca (No default value)
ssl-capath (No default value)
ssl-cert (No default value)
ssl-cipher (No default value)
ssl-key (No default value)
ssl-verify-server-cert FALSE
tab (No default value)
triggers TRUE
tz-utc TRUE
user (No default value)
verbose FALSE
where (No default value)