WD1X.COM - 问答一下,轻松解决,电脑应用解决专家
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win11Linux
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascript服务器
PHP教程CSS教程XML教程

Mysqldump命令参数介绍

更新时间:2021-06-29 16:15 作者:新闻联播老司机点击:

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 常用参数

备份数据库


[root@abcdocker ~]# mysqldump -uroot -p --hex-blob --routines --triggers --single-transaction --default-character-set=utf8 wordpress >1.sql

 

--hex-blob = 备份二进制文件  

--routines = 备份函数  

--triggers = 备份触发器  

--single-transaction = 开启单实例(针对innodb,innodb不需要锁表)  

--default-character-set=utf8 =指定字符集  

wordpress = 备份的库名称  

备份表文件


[root@abcdocker ~]# mysqldump -uroot -p --hex-blob --routines --triggers --single-transaction --default-character-set=utf8 wordpress 表名 >1.sql


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.

附加注释信息。默认为打开,可以用--skip-comments取消


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 相兼容.值可以为ansimysql323mysql40postgresqloraclemssqldb2maxdbno_key_optno_tables_optionsno_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 --debug

mysqldump -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=, MASTER_PORT=' to 'CHANGE

MASTER TO..' in dump produced with --dump-slave.

--dump-slave产生的CHANGE MASTER TO ....语句中增加'MASTER_HOST=,MASTER_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表并行插入.对于支持事务的表例如InnoDBBDB--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/IPsocket连接的缓存大小


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-database

mysqldump -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 ( ) 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

直接输出到指定文件中。该选项应该用在使用回车换行对( )换行的系统上(例如: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-databases

mysqldump -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

指定连接mysqlsocket文件位置,默认路径/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/"

客户端插件默认使用


82、--enable-cleartext-plugin

Enable/disable the clear text authentication plugin.

启用/禁用 明文的身份验证插件

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
你可能感兴趣的内容