mysqldump 工具使用详解——参数选项
mysqldump 简介
mysqldump 是一种用于逻辑备份的客户端工具,它会产生一套能够重新构建数据库或表的SQL语句。所谓逻辑备份:是利用SQL语言从数据库中抽取数据并存于二进制文件的过程。逻辑备份文件只能用来对数据库进行逻辑恢复,即数据导入,而不能按数据库原来的存储特征进行物理恢复。
用mysqldump进行备份的用户账号至少需要SELECT权限来dump表、SHOW VIEW权限dump视图、TRIGGER权限dump触发器、如果没有使用--single-transaction选项还需要LOCK TABLES权限(后面会讲到--single-transaction选项不会锁表),另外某些选项可能还需要其他权限,可在官方手册查询。
mysqldump 备份格式大概可分为3种:
shell> mysqldump [options] db_name [tbl_name ...] #备份指定数据库或表
shell> mysqldump [options] --databases db_name ... #备份指定数据库
shell> mysqldump [options] --all-databases #备份所有数据库
mysqldump 选项(来源于mysql 5.7手册)
--add-drop-database
Add DROP DATABASE statement before each CREATE DATABASE statement (每个数据库创建之前添加drop数据库语句)
--add-drop-table
Add DROP TABLE statement before each CREATE TABLE statement (每个数据表创建之前添加drop table语句。默认为打开状态,使用--skip-add-drop-table取消选项)
--add-drop-trigger
Add DROP TRIGGER statement before each CREATE TRIGGER statement
--add-locks
Surround each table dump with LOCK TABLES and UNLOCK TABLES statements (在每个表导出之前增加LOCK TABLES并且之后UNLOCK TABLES。默认为打开状态,使用--skip-add-locks取消选项)
--all-databases (-A)
Dump all tables in all databases (备份所有数据库的所有表)
--allow-keywords
Allow creation of column names that are keywords
--apply-slave-statements Include
STOP SLAVE prior to CHANGE MASTER statement and START SLAVE at end of output
--bind-address
Use specified network interface to connect to MySQL Server
--character-sets-dir
Directory where character sets are installed
--comments
Add comments to dump file
--compact
Produce more compact output
--compatible
Produce output that is more compatible with other database systems or with older MySQL servers
--complete-insert, -c
Use complete INSERT statements that include column names(使用完整的insert语句(包含列名称)。这么做能提高插入效率,但是可能会受到 max_allowed_packet 参数的影响而导致插入失败)
--compress
Compress all information sent between client and server
--create-options
Include all MySQL-specific table options in CREATE TABLE statements
--databases (-B)
Interpret all name arguments as database names (将选项后的所有名称参数解释为数据库名称,以空格隔开)
注意:如果dump时不加 --databases 参数而直接跟数据库名,则备份的sql文件中不会打印 "CREATE DATABASE ..." 语句和 "USE `db_name`;" 语句。
--debug
Write debugging log
--debug-check
Print debugging information when program exits
--debug-info
Print debugging information, memory, and CPU statistics when program exits
--default-auth
Authentication plugin to use
--default-character-set
Specify default character set
--defaults-extra-file
Read named option file in addition to usual option files
--defaults-file
Read only named option file
--defaults-group-suffix
Option group suffix value
--delete-master-logs
On a master replication server, delete the binary logs after performing the dump operation
--disable-keys
For each table, surround INSERT statements with statements to disable and enable keys
--dump-date
Include dump date as "Dump completed on" comment if --comments is given
--dump-slave
Include CHANGE MASTER statement that lists binary log coordinates of slave's master (取值0,1,2,与master-data作用相同)
# mysqldump -uroot -proot --single-transaction --dump-slave=2 -A > all.sql
在从库进行备份时,指定--dump-slave会在备份的sql中生成带有主库binlog位置的CHANGE MASTER语句;如果要给主库新增从库,可以在从库这样进行备份。
--enable-cleartext-plugin
Enable cleartext authentication plugin 5.7.10
--events
Dump events from dumped databases
--extended-insert, -e
Use multiple-row INSERT syntax (扩展插入,一条 insert 包含多条数据)
--fields-enclosed-by
This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE
--fields-escaped-by
This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE
--fields-optionally-enclosed-by
This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE
--fields-terminated-by
This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE
--flush-logs
Flush MySQL server log files before starting dump
--flush-privileges
Emit a FLUSH PRIVILEGES statement after dumping mysql database
--force
Continue even if an SQL error occurs during a table dump
--help
Display help message and exit
--hex-blob
Dump binary columns using hexadecimal notation
--host (-h)
Host to connect to (IP address or hostname) mysqldump 支持远程备份和远程恢复(可远程导表)。
--ignore-error
Ignore specified errors 5.7.1
--ignore-table
Do not dump given table (不导出指定表。指定忽略多个表时,需要重复多次,每次一个表。每个表必须同时指定数据库和表名。例如:--ignore-table=database.table1 --ignore-table=database.table2 ……)
--include-master-host-port
Include MASTER_HOST/MASTER_PORT options in CHANGE MASTER statement produced with --dump-slave
--insert-ignore
Write INSERT IGNORE rather than INSERT statements
--lines-terminated-by
This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE
--lock-all-tables (-x)
Lock all tables across all databases (请求锁定所有数据库中的所有表,以保证数据的一致性。这是一个全局读锁,并且自动关闭--single-transaction 和--lock-tables 选项)
--lock-tables
Lock all tables before dumping them
--log-error
Append warnings and errors to named file
--login-path
Read login path options from .mylogin.cnf
--master-data
Write the binary log file name and position to the output (该选项将binlog的位置和文件名追加到输出文件中。如果为1,将会输出CHANGE MASTER 命令;如果为2,输出的CHANGE MASTER命令前添加注释信息。该选项将打开--lock-all-tables 选项,但当--single-transaction也被指定时,在开始导出时会获得很短的时间的全局读锁;其他内容参考下面的--single-transaction选项。该选项自动关闭--lock-tables选项)
--max_allowed_packet
Maximum packet length to send to or receive from server
--net_buffer_length
Buffer size for TCP/IP and socket communication
--no-autocommit
Enclose the INSERT statements for each dumped table within SET autocommit = 0 and COMMIT statements
--no-create-db (-n)
Do not write CREATE DATABASE statements (只导出数据,而不添加CREATE DATABASE 语句)
--no-create-info (-t)
Do not write CREATE TABLE statements that re-create each dumped table (只导出数据,而不添加CREATE TABLE 语句)
--no-data (-d)
Do not dump table contents (只生成创建表结构的语句,不导出数据)
--no-defaults
Read no option files (不会读取任何配置文件。如果由于从配置文件读取未知选项而导致程序启动失败,可以使用--no-defaults来防止它们被读取)
--no-set-names
Same as --skip-set-charset
--no-tablespaces
Do not write any CREATE LOGFILE GROUP or CREATE TABLESPACE statements in output
--opt
Shorthand for --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset.
--order-by-primary
Dump each table's rows sorted by its primary key, or by its first unique index (mysqldump 导出时根据主键或唯一索引排序,以加快导入速度)
--password
Password to use when connecting to server
--pipe
On Windows, connect to server using named pipe
--plugin-dir
Directory where plugins are installed
--port
TCP/IP port number to use for connection
--print-defaults
Print default options
--protocol
Connection protocol to use
--quick
Retrieve rows for a table from the server a row at a time (不缓冲查询,直接导出到标准输出。默认为打开状态,使用--skip-quick取消该选项)
--quote-names
Quote identifiers within backtick characters
--replace
Write REPLACE statements rather than INSERT statements
--result-file
Direct output to a given file
--routines
Dump stored routines (procedures and functions) from dumped databases
--secure-auth
Do not send passwords to server in old (pre-4.1) format
--set-charset
Add SET NAMES default_character_set to output
--set-gtid-purged = [off | on]
Whether to add SET @@GLOBAL.GTID_PURGED to output (--set-gtid-purged=OFF 设置备份文件中不存储GTIDs,如果不设置,恢复时可能报错:ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty. 这时需要执行 reset master,清除GTID_EXECUTED的值)
--shared-memory-base-name
The name of shared memory to use for shared-memory connections
--single-transaction
Issue a BEGIN SQL statement before dumping data from server (该选项在导出数据之前提交一个BEGIN SQL语句,且不锁表,BEGIN 不会阻塞任何应用程序且能保证导出时数据库的一致性状态。它只适用于多版本存储引擎,仅InnoDB。本选项和--lock-tables 选项是互斥的,因为LOCK TABLES 会使任何挂起的事务隐含提交。要想导出大表的话,应结合使用--quick 选项。)
--skip-add-drop-table
Do not add a DROP TABLE statement before each CREATE TABLE statement
--skip-add-locks
Do not add locks
--skip-comments
Do not add comments to dump file
--skip-compact
Do not produce more compact output
--skip-disable-keys
Do not disable keys
--skip-extended-insert
Turn off extended-insert (关闭扩展插入,即sql文件中,一行只有一个insert....value())
--skip-opt
Turn off options set by --opt
--skip-quick
Do not retrieve rows for a table from the server a row at a time
--skip-quote-names
Do not quote identifiers
--skip-set-charset
Do not write SET NAMES statement
--skip-triggers
Do not dump triggers
--skip-tz-utc
Turn off tz-utc
--socket
For connections to localhost, the Unix socket file to use
--ssl
Enable secure connection
--ssl-ca
Path of file that contains list of trusted SSL CAs
--ssl-capath
Path of directory that contains trusted SSL CA certificates in PEM format
--ssl-cert
Path of file that contains X509 certificate in PEM format
--ssl-cipher
List of permitted ciphers to use for connection encryption
--ssl-crl
Path of file that contains certificate revocation lists
--ssl-crlpath
Path of directory that contains certificate revocation list files
--ssl-key
Path of file that contains X509 key in PEM format
--ssl-mode
Security state of connection to server 5.7.11
--ssl-verify-server-cert
Verify server certificate Common Name value against host name used when connecting to server
--tab=dir_name (-T dir_name)
Produce tab-separated data files (生成制表符分隔的文本格式数据文件。对于每个dump表,mysqldump会创建一个 tbl_name.sql 文件,其中包含创建表的CREATE TABLE语句,并且会创建一个包含该表数据的 tbl_name.txt 文件,选项值是写入文件的目录。即表结构与数据分离。默认情况下,.txt数据文件使用制表符分隔每列,换行分隔每行。也可以使用--fields-terminated-by=',' 和 --lines-terminated-by='\n\n' 明确指定分隔符)
--tables
Override --databases or -B option (覆盖--databases或-B选项。mysqldump将该选项后面的所有名称参数视为表名)
--tls-version
Protocols permitted for secure connections 5.7.10
--triggers
Dump triggers for each dumped table
--tz-utc
Add SET TIME_ZONE='+00:00' to dump file
--user
MySQL user name to use when connecting to server
--verbose
Verbose mode
--version
Display version information and exit
--where (-w)
Dump only rows selected by given WHERE condition (根据条件备份指定的行,如 --where="uid=123 and name='xxx'")
--xml
Produce XML output
mysqldump 工具使用详解——参数选项的更多相关文章
- MySQL数据库使用mysqldump导出数据详解
mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等.接下来通过本文给大家介绍MySQL数 ...
- [转]网络性能评估工具Iperf详解(可测丢包率)
原文链接:安全运维之:网络性能评估工具Iperf详解:http://os.51cto.com/art/201410/454889.htm 参考博文:http://linoxide.com/monito ...
- 批量执行工具PSSH详解
批量执行工具PSSH详解 pssh是一个python编写可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的,使用必须在各个服务器上配置好密钥认证访问. 安装pssh包 yum 安 ...
- 自动化运维工具——ansile详解
自动化运维工具——ansible详解(一) 目录 ansible 简介 ansible 是什么? ansible 特点 ansible 架构图 ansible 任务执行 ansible 任务执行模式 ...
- MySQLdump之single-transaction详解
MySQLdump之single-transaction详解 single-transaction 开启general log选项 查看目前general log的情况 mysql> show ...
- Linux备份数据库,mysqldump命令实例详解
mysqldump是mysql数据库中备份工具,用于将MYSQL服务器中的数据库以标准的sql语言的方式导出,并保存到文件中. 语法: mysqldump (选项) 选项: --add-drop-ta ...
- IE8"开发人员工具"使用详解下(浏览器模式、文本模式、JavaScript调试、探查器)
来源: http://www.cnblogs.com/JustinYoung/archive/2009/04/03/kaifarenyuangongju2.html 在上一篇文章IE8“开发人员工具” ...
- 【Android 应用开发】Ubuntu 下 Android Studio 开发工具使用详解 (旧版本 | 仅作参考)
. 基本上可以导入项目开始使用了 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21035637 ...
- 【Android 应用开发】Ubuntu 下 Android Studio 开发工具使用详解
. 基本上可以导入项目开始使用了 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21035637 ...
随机推荐
- C#json数据的序列化和反序列化(将数据转换为对象或对象集合)
引用 System.Runtime.Serialization.Json
- Ubuntu E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它? 不要删掉这些目录!! ...
- Umbrella Header for Module Bolts does not include header 'XXXXXX.h'?
在我们引入第三方Framwork时.有时会出现如标题的警告提示? 怎样解决? Framework 将在下面文件夹下创建一个Module/,并创建一个module.modulemap文件 waterma ...
- POJ 2524 Ubiquitous Religions (幷查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23090 Accepted: ...
- openwrt gstreamer实例学习笔记(二.gstreamer 的 Element)
对程序员来说,GStreamer 中最重要的一个概念就是 GstElement 对象.该对象是构建一个媒体管道的基本块.所有上层(high-level)部件都源自GstElement对象.任何一个解码 ...
- Arcgis Engine(ae)接口详解(3):featureClass的feature编辑和删除
//由于测试数据不完善,featureClass在此要只设null值,真实功能要设实际的值 IFeatureClass featureClass = null; //获取某个字段的索引,后面取字段值用 ...
- [网页游戏开发]进一步了解Morn UI及工作流
Morn UI工作流 Morn Builder不仅仅是对Flash IDE的改进,传统的开发协作是以fla为基础,由于fla是二进制文件,在以svn等版本控制软件协作下,合并过程中会出现各种各样的问题 ...
- 基于redis集群实现的分布式锁,可用于秒杀商品的库存数量管理,有測试代码(何志雄)
转载请标明出处. 在分布式系统中,常常会出现须要竞争同一资源的情况,本代码基于redis3.0.1+jedis2.7.1实现了分布式锁. redis集群的搭建,请见我的另外一篇文章:<>& ...
- SpringInAction4笔记——装配
重点:常用的上下文环境 AnnotationConfigApplicationContext ClassPathXmlApplicationContext FileSystemXmlApplicati ...
- ivy
ivy https://ant.apache.org/ivy/ Apache Ivy™ is a popular dependency manager focusing on flexibility ...