先看一下--lock-tables和--lock-all-tables

--lock-all-tables

一次性锁定所有数据库的所有表,在整个dump期间一直获取global read lock;

该选项自动关闭—lock-tables和—single-transaction;

--lock-tables

以database为单位,dump前锁定其下所有表;如果是Myisam表则采用 read local模式,允许同时insert;

--opt自动启用—lock-tables;

注:--opt包含--add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset

再看一下官方对于single-transaction的解释

--single-transaction

This option sets the transaction isolation mode to REPEATABLE READ and sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time when START TRANSACTION was issued without blocking any applications.

When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state.

While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection should use the following statements: ALTER TABLE, CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the SELECT that is performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.

The --single-transaction option and the --lock-tables option are mutually exclusive because LOCK TABLES causes any pending transactions to be committed implicitly.

To dump large tables, combine the --single-transaction option with the --quick option.

可以总结出以下几点:

1 只适用于innodb;

2 需要repeatable read模式开启一个事务

3 执行期间不阻碍DML和DDL,但是不要人工执行alter/create/drop/rename/truncate table;

4  不能与lock-tables共用,后者执行的LOCK TABLES会隐式提交所有pending事务

执行流程

(1)SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ

(2)START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */

(3)UNLOCK TABLES

如果mysqldump只指定single-transaction,期间不会加锁也不会阻止任何的事务;

--master-data

默认启用—lock-all-tables,如果显示指定—single-transaction则弃用—lock-all-tables,此时只在dump开始时短暂获取global read lock;

执行流程

(1)FLUSH  TABLES

(2)FLUSH TABLES WITH READ LOCK

(3)SHOW MASTER STATUS

同时使用Master-data和single-transaction可以对Innodb进行Online backup

shell> mysqldump --all-databases --master-data --single-transaction > all_databases.sql

执行流程

(1)FLUSH   TABLES

(2)FLUSH TABLES WITH READ LOCK

(3)SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ

(4)START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */

(5)SHOW MASTER STATUS

(6)UNLOCK TABLES

global read lock的持续时间很短,获取当前binlog的位置信息后立即释放;

注意:

在执行时如果当前有一个事务长时间没有结束,那么FLUSH TABLES WITH READ LOCK将会一直等待,而更加严重的是,阻塞的FLUSH TABLES WITH READ LOCK会进一步阻塞后续的DML,从而造成mysql hang;

--dump-slave

5.5引入了dump-slave选项,可对slave执行mysqldump,得出的change master to却是指向master,即使用slave创建一个新的slave;

执行期间会停止slave sql thread,完成后自动恢复;

 MDL
5.5有了MDL(Meta data lock),所以–single-transaction时,事务内操作过的表都会持有MDL,因此不会被DDL破坏。
例如,mysqldump已经备份了a,b,c表,因为它们在事务内,事务还没提交,它们的MDL不会释放,因此另外的线程如果做a,b,c中任意一张表的DDL操作,都会出现Waiting for table metadata lock,而还没备份到的表不会持有MDL,因此还可以做DDL。
http://www.penglixun.com/tech/database/the_process_of_mysqldump.html

【转载】mysqldump的single-transaction和master-data的更多相关文章

  1. HR数据抽取:通过 Read Master Data 转换规则读取时间相关主属性数据

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. Article Master Data Deviation

    Site data – Logistics DC / Logistics Store Where is the reference site decided when you maintain the ...

  3. QM模块包含主数据(Master data)和功能(functions)

    QM模块包含主数据(Master data)和功能(functions)   QM主数据   QM主数据 1 Material   Master MM01/MM02/MM50待测 物料主数据 2 Sa ...

  4. MS MDS系列之初始MS Master Data Service(微软主数据服务)

    背景介绍: 主数据服务(Master Data Services)是微软平台支持的主数据管理(MDM)平台.类似MDS这样的系统,如果后续维护得当,会给企业提供一个强大的中心数据库系统,来防止企业数据 ...

  5. Linux C single linked for any data type

    /************************************************************************** * Linux C single linked ...

  6. 转载 JQuery中attr属性和JQuery.data()学习

    转载原地址: http://www.cnblogs.com/yeminglong/p/5405745.html 用html直接data-key来存放,key必须全部小写. <div data-m ...

  7. mysql 在 win 安装 最全攻略(附转载的乱码终极解决方案)以及解决data too long for column 'name' at row 1, 一种可能就是因为编码一致性问题.

    [博客园cnblogs笔者m-yb原创,转载请加链接,公众号aandb7, github.com/mayangbo666,QQ群927113708] https://www.cnblogs.com/m ...

  8. [转]Wrapping multiple calls to SaveChanges() in a single transaction

    本文转自:http://www.binaryintellect.net/articles/165bb877-27ee-4efa-9fa3-40cd0cf69e49.aspx When you make ...

  9. How do I extract a single column from a data.frame as a data.frame

    Say I have a data.frame: df <- data.frame(A=c(10,20,30),B=c(11,22,33), C=c(111,222,333))  A  B  C ...

  10. 【OCP-12c】2019年CUUG OCP 071考试题库(79题)

    79.Which statement is true about transactions? A. A set of Data Manipulation Language (DML) statemen ...

随机推荐

  1. VMware系统运维(十)部署虚拟化桌面 Horizon View 5.2 Connection Server安装

    部署桌面虚拟化,首先得安装连接服务器,下面我们开始安装Connection Server. 1.下载并安装以下软件,提示:只能在Win2008R2上安装,Win2012R2无法安装. 2.双击打开程序 ...

  2. JavaScript对Json的增删改属性

    <script type="text/javascript"> var json = { "age":24, "name":&q ...

  3. 以NameValueCollection 修改URL中的查询参数

    以NameValueCollection 修改URL中的查询参数 本文参考于:http://www.c-sharpcorner.com/Blogs/9421/add-remove-or-modify- ...

  4. 【Dijkstra】

    [摘自]:华山大师兄,推荐他的过程动画~   myth_HG 定义 Dijkstra算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩 ...

  5. #316 div.2

    主要记录下被坑的B.果然大晚上脑子就是不知道在干嘛,明明都测到 “1 1” 这个样例错了都没发现直接给放过去了,白白让人hack爽了... 题意就是给你一个数m,让你从1~n个数中选一个作a,使1~n ...

  6. 正则表达式删除指定的HTML 标签

    1.抓取某网页的数据后(比如描述),如果照原样显示的话,可能会因为它里面包含没有闭合的HTML标签而打乱了格式,也可能它里面用了比较让人 "费解" 的HTML标签,把预订的格式搅乱 ...

  7. C#_枚举类型

     C#中的枚举是名/值对的数据类型,下面是自定义的军衔等级的枚举 //定义枚举 enum MilitaryRank { Commander, ArmyCorpCommander, Military ...

  8. 百度编辑器ueditor前台代码高亮无法自动换行解决方法

    这两天本站成功安装整合了百度编辑器ueditor,用着还挺不错,但是遇到了点小问题 问题描述:   在内容里面插入代码高亮显示,后台编辑器中是可以自动换行的,但是发表后,在前台查看,发现代码不能自动换 ...

  9. 第九篇、自定义底部UITabBar

    国际惯例先上图: 代码实现(在UITabBarViewController设置): - (void)setUpTabBar { LHLTabBar *tabBar = [[LHLTabBar allo ...

  10. 初识iOS9 iPad新特性SlideView和SplitView的适配

    苹果刚发布了iOS9,在iPad上新增了两个新的特性SlideView和SplitView,前者可以在不关闭当前激活APP的情况下调出来另外个APP以30%比例显示进行操作使用,后者允许同时运行两个A ...