在前一篇文章中,有提到mysqldump的--single-transaction参数。
另外还有个很重要,也是运维中经常用到的参数:--master-data,网上很多关于MySQL不停机备份的实现都有它的身影。
翻译下man mysqldump中--master-data相关的章节,以便加强理解

? --master-data[=value]

Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master.

It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server.

These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave.

使用此选项dump a master replication server到dump文件,可用于设立另一台服务器作为master的slave。

它会使dump输出包含CHANGE MASTER TO语句,标记dump源的二进制日志坐标(文件名和位置)。

在把load dump文件加载到slave之后,slave应当从该master坐标开始复制。

If the option value is 2, the CHANGE MASTER TO statement is written as an SQL comment, and thus is informative only; it has no effect when the dump file is reloaded.

If the option value is 1, the statement is not written as a comment and takes effect when the dump file is reloaded.

If no option value is specified, the default value is 1.

如果选项赋值为2,那么CHANGE MASTER TO 语句会被写成一个SQL comment(注释),从而只提供信息;

如果选项赋值为1,那么语句不会被写成注释并且在dump被载入时生效。

如果没有指定,默认值为1。

This option requires the RELOAD privilege and the binary log must be enabled.

这个选项要求 RELOAD 权限,并且二进制文件必须打开。

The --master-data option automatically turns off --lock-tables.

It also turns on --lock-all-tables, unless --single-transaction also is specified, in which case, a global read lock is acquired only for a short time at the beginning of the dump (see the description for --single-transaction).

In all cases, any action on logs happens at the exact moment of the dump.

--master-data 选项会自动关闭 --lock-tables。

也会打开 --lock-all-tables,除非指定--single-transaction,如果那样的话,在开始dump时会获取一个全局read lock 一小段时间(详见--single-transaction的描述)。

不论什么情况下,日志相关动作发生在dump的确切时刻。——没懂

It is also possible to set up a slave by dumping an existing slave of the master.

To do this, use the following procedure on the existing slave:

它也可以dump一个存在的slave来设立一个新的slave。

要做到这点,在已存在的slave使用如下的步骤:

1. Stop the slave?s SQL thread and get its current status:

停止slave的SQL 线程并获取它的当前状态

mysql> STOP SLAVE SQL_THREAD;
mysql> SHOW SLAVE STATUS;

2. From the output of the SHOW SLAVE STATUS statement, the binary log coordinates of the master server
from which the new slave should start replicating are the values of the Relay_Master_Log_File and
Exec_Master_Log_Pos fields. Denote those values as file_name and file_pos.

从SHOW SLAVE STATUS语句的输出,新slave应当开始复制master二进制的坐标就是 Relay_Master_Log_File 和 Exec_Master_Log_Pos 的值。

用 file_name 和 file_pos 表示这些值。

3. Dump the slave server:

shell> mysqldump --master-data=2 --all-databases > dumpfile

Using --master-data=2 works only if binary logging has been enabled on the slave.

Otherwise, mysqldump fails with the error Binlogging on server not active.

In this case you must handle any locking issues in another manner, using one or more of --add-locks, --lock-tables, --lock-all-tables, or --single-transaction, as required by your application and environment.

仅在已打开二进制日志的slave上使用--master-data=2。

否则mysqldump会报错二进制日志未启动。

这种情况下你必须以另一种方式来处理任何锁定问题,根据你应用和环境来决定使用--add-locks, --lock-tables, --lock-all-tables,or --single-transaction中的一个或多个。

4. Restart the slave:

mysql> START SLAVE;

5. On the new slave, load the dump file:

shell> mysql < dumpfile

6. On the new slave, set the replication coordinates to those of the master server obtained earlier:

在新slave上,设置之前从master获取的复制坐标

mysql> CHANGE MASTER TO
-> MASTER_LOG_FILE = ?file_name?, MASTER_LOG_POS = file_pos;

The CHANGE MASTER TO statement might also need other parameters, such as MASTER_HOST to point the slave to the correct master server host. Add any such parameters as necessary.
CHANGE MASTER TO语句也需要其他参数,比如 MASTER_HOST 来指定slave连接正确的master。按需增加其他参数
------------------------

? --delete-master-logs

On a master replication server, delete the binary logs by sending a PURGE BINARY LOGS statement to the server after performing the dump operation. This option automatically enables --master-data.

在master replication server 执行dump操作后,通过发送一个 PURGE BINARY LOGS 语句到服务器来删除二进制日志。

该选项自动启用--master-data。

------------------------

? --flush-logs, -F

Flush the MySQL server log files before starting the dump. This option requires the RELOAD privilege.

If you use this option in combination with the --all-databases option, the logs are flushed for each database dumped.

The exception is when using --lock-all-tables or --master-data: In this case, the logs are flushed only once, corresponding to the moment that all tables are locked.

If you want your dump and the log flush to happen at exactly the same moment, you should use --flush-logs together with either --lock-all-tables or --master-data.

在开始dump之前flush mysql 日志文件。该选项需要 RELOAD 权限。

如果你将该选项与 --all-databases 结合使用,每个数据库的日志都会被flush for dump。

例外是当使用 --lock-all-tables 或 --master-data,这种情况下,日志会被flush一次,对应于所有表锁定的那一刻。

如果你希望dump 和 log flush 发生在完全相同的时刻,你应该把 --flush-logs 连同 --lock-all-tables 或 --master-data使用。

------------------------

This backup acquires a global read lock on all tables (using FLUSH TABLES WITH READ LOCK) at the beginning of the dump.

As soon as this lock has been acquired, the binary log coordinates are read and the lock is released.

If long updating statements are running when the FLUSH statement is issued, the MySQL server may get stalled until those statements finish.

After that, the dump becomes lock free and does not disturb reads and writes on the tables.

If the update statements that the MySQL server receives are short (in terms of execution time), the initial lock period should not be noticeable, even with many updates.

此备份在dump开始的时候就获得所有表的全局读锁定(使用FLUSH TABLES WITH READ LOCK)。
当锁一旦被获取,就读取二进制日志坐标并释放锁。
如果执行FLUSH语句时有很长的update语句正在执行,MySQL会直到等那些语句完成才会get stalled(失速/抛锚,停止?)。
在此之后,dump 变得 lock free 并且不再妨碍读写表。

如果MySQL服务器接收update语句很短(在执行时间),初步锁定期并不明显,即使有很多的update。

For point-in-time recovery (also known as "roll-forward," when you need to restore an old backup and replay the changes that happened since that backup), it is often useful to rotate the binary log (see Section 5.2.4, "The Binary Log") or at least know the binary log coordinates to which the dump corresponds:

对于即时恢复(也称为“roll-forward”,当你需要恢复旧的备份并重放从备份之后发生的变化),这是经常用于循环二进制日志(参见第5.2.4,“二进制日志”)或至少知道二进制日志坐标到dump对应关系:

shell> mysqldump --all-databases --master-data=2 > all_databases.sql

Or:

shell> mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql

The --master-data and --single-transaction options can be used simultaneously, which provides a convenient way to make an online backup suitable for use prior to point-in-time recovery if tables are stored using the InnoDB storage engine.

--master-data 和 --single-transaction 选项可同时使用,如果表使用InnoDB存储引擎,它提供了简便的途径来制作适用于定点恢复的在线备份。

mysqldump详解之--master-data的更多相关文章

  1. MySQL程序之mysqldump详解

    mysqldump命令详解 mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等 用法: ...

  2. MySQL(十五)之数据备份中mysqldump详解

    前言 其实前面一篇数据备份已经是非常的详细了,这里我想单独的讲解一下mysqldump,相信很多程序员都是用过这个命令的! 一.MySQL数据库的备份与还原 1.1.MySQL数据库备份 1)语法 m ...

  3. mysqldump详解

    Ⅰ.mysqldump的简单使用与注意点 1.1 基本参数 只备份innodb,用不了几个参数,记住下面几个即可,其他的没什么卵用 -A 备份所有的database -B 备份哪几个数据库 -R 备份 ...

  4. jquery方法详解--bind(type, [data], fn)

    转自:http://www.zhufengpeixun.cn/jquery/bind_type_data_fn.html bind(type, [data], fn)  返回值::jQuery 概述 ...

  5. Mysql的mysqldump详解

    一.导出 1.1 导出表结构及数据 mysqldump -uroot -p --set-gtid-purged=OFF database table1 table2 > mysqldump.sq ...

  6. 【翻译】详解HTML5 自定义 Data 属性

    原标题:HTML5 Custom Data Attributes (data-*) 你是否曾经使用 class 或 rel 来保存任意的元数据,只为了使你的JavaScript更简单?如果你回答是的, ...

  7. MySQL数据备份 mysqldump 详解

    MySQL数据备份流程 1 打开cmd窗口 通过命令进行数据备份与恢复: 需要在Windows的命令行窗口中进行: l 开始菜单,在运行中输入cmd回车: l 或者win+R,然后输入cmd回车,即可 ...

  8. python之模块datetime详解

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之模块datetime详解 import datetime #data=datetime.dat ...

  9. OSPF详解

    OSPF 详解 (1) [此博文包含图片] (2013-02-04 18:02:33) 转载 ▼ 标签: 端的 第二 以太 第一个 正在 目录 序言 初学乍练 循序渐进学习OSPF 朱皓 入门之前 了 ...

随机推荐

  1. 初窥Java之一

    一.常用的dos命令 打开命令提示符窗口的方式: ① win + R --> 输入cmd --> 回车 ② 开始 --> 搜索程序和文件的框中输入  cmd  --> 回车 ③ ...

  2. 牛客练习赛35-背单词-线性DP

    背单词 思路 :dp[ i ]  [ 0 ]表示 第i 位放的元音  dp[ i ]  [ 1 ]表示 第i 位放的辅音 ,cnt [ i ]含义是 长度为 i 的方案数. 转移  :dp[ i ]  ...

  3. jquery利用正则表达式验证密码,手机号(主要是使用方法,正则表达式网上一搜一堆)

    var mobile = $("#UserMobile").val(); if (mobile != "") { }-\d{}|\d{}-\d{,})|([|| ...

  4. BZOJ.5288.[AHOI/HNOI2018]游戏(思路 拓扑)

    BZOJ LOJ 洛谷 考虑如何预处理每个点能到的区间\([l,r]\). 对于\(i,i+1\)的一扇门,如果钥匙在\(i\)的右边,连边\(i\to i+1\),表示从\(i\)出发到不了\(i+ ...

  5. Java笔记(三)异常

    异常 一.概念 一)为什么会有Java异常机制 在没有Java异常机制的情况下,唯一的退出机制就是返回值,判断是否异常的方法就是 返回值.方法根据是否异常返回不同的返回值,调用者根据不同的返回值进行判 ...

  6. JavaScript基础笔记(四) JS式面向对象

    JS式面向对象 一.理解对象 一)属性类型 ECMA-262 第 5 版在定义只有内部才用的特性(attribute)时,描述了属性(property)的各种特征. ECMA-262 定义这些特性是为 ...

  7. Centos ATI 显卡安装,“LCD 信号超出范围” 解决方法

    centso ATI 显卡驱动安装 centos 版本 32位 6.4 Final ATI 显卡版本:Radeon HD 7400 Series 之前由于很久自己安装了centos显卡,分辨率很低不能 ...

  8. [USACO08JAN]牛大赛Cow Contest

    OJ题号:洛谷2419 思路: Floyd求有向图的传递闭包,只要该点与其他所有点相连即可确定名次. #include<cstdio> #include<cstring> in ...

  9. 读《31天学会CRM项目开发》记录1 - 认识软件开发

    今天闲来无事,心中又对软件开发充满了向往和憧憬.一直认为实践是检验真知的唯一标准,也是快速提升的绝密方法,是巩固基础加深基础的好去处.故在JD上搜了下软件开发,看到了这本<31天学会CRM项目开 ...

  10. array中key所对应的value

    获取数组中的键对应的值 class Test{ public function index(){ $info = array( 'name' => 'daicr', 'age' => 24 ...