--master log 与relay log的关系

-------------------------------2014/06/09

Just to clarify, there are three sets of file/position coordinates in SHOW SLAVE STATUS:

1) The position, ON THE MASTER, from which the I/O thread is reading: Master_Log_File/Read_Master_Log_Pos. -----相对于主库,从库读取主库的二进制日志的位置,是IO线程

2) The position, IN THE RELAY LOGS, at which the SQL thread is executing: Relay_Log_File/Relay_Log_Pos ----相对于从库,是从库的sql线程执行到的位置

3) The position, ON THE MASTER, at which the SQL thread is executing: Relay_Master_Log_File/Exec_Master_Log_Pos ----相对于主库,是从库的sql线程执行到的位置

Numbers 2) and 3) are the same thing, but one is on the slave and the other is on the master.

mysql > show slave status \G

Master_Log_File: mysql-bin-m.000329

    Read_Master_Log_Pos: 863952156----上面二行代表IO线程,相对于主库

Relay_Log_File: mysql-relay.003990

    Relay_Log_Pos: 25077069—上面二行代表了sql线程,相对于从库

Relay_Master_Log_File: mysql-bin-m.000329

    Exec_Master_Log_Pos: 863936961---上面二行代表了sql线程,相对主库

    (为了方便演示,我把上面这行提前了.)

    Relay_Log_Space: 25092264---当前relay-log文件的大小

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

从上面可以看到,read_master_log_pos 始终会大于exec_master_log_pos的值:因为一个值是代表io线程,一个值代表sql线程;sql线程肯定在io线程之后.(当然,io线程和sql线程要读写同一个文件,否则比较就失去意义了) .在binlog中,Xid代表了提交的事务号.现在我们分别去主从库看看,验证一下,在主库的mysql-bin-m.000329文件的863936961处是否与从库的mysql-relay.003990文件的25077069处有相同的sql语句, 先看主库的binlog:

# at 863936961

#100111 20:11:39 server id 115000 end_log_pos 863937234        Query   thread_id=515886        exec_time=0 error_code=0

use mall00/*!*/;

UPDATE mall00.t_item_sid88 SET item_end_time = 1263816699, item_is_online = 1, item_status = 1 WHERE iid IN (94322390, 94322428, 94322452, 94322473, 94322506, 94322532, 94322604, 94322641, 94322670, 94322706)/*!*/;

# at 863937234

#100111 20:11:39 server id 115000 end_log_pos 863937261        Xid = 1225244590

COMMIT/*!*/;

# at 863937261

再看从库的relaylog:

# at 25077069

#100111 20:11:39 server id 115000 end_log_pos 863937234        Query   thread_id=515886        exec_time=0 error_code=0

use mall00/*!*/;

UPDATE mall00.t_item_sid88 SET item_end_time = 1263816699, item_is_online = 1, item_status = 1 WHERE iid IN (94322390, 94322428, 94322452, 94322473, 94322506, 94322532, 94322604, 94322641, 94322670, 94322706)/*!*/;

# at 25077342

#100111 20:11:39 server id 115000 end_log_pos 863937261        Xid = 1225244590

COMMIT/*!*/;

从上面的日志中,可以看到binlog与realy-log的内容是相同的,除了开头的at位置处的偏移量.因为偏移量始终是相对于文件自身来说,主库上相对于binlog本身,从库上相对于relay-log本身.还可以看到,在每个query语句过后,都有一个Xid 的event,提交该事务,也表明在mysql中是自动提交的,每条语句执行完毕后,系统都自动提交了.那么在基于行的复制中,可能会看到多条binlog 语句才对应一次commit,自然说明这是基于行的复制.

还有一点,就是主库和从库的对应位置的event大小是相同的

例如上面的:

25077342-25077069(从库上event大小) = 863937234-863936961(主库上event大小)

否则,说明从库的relay-log丢失了,有可能是操作系统缓存丢失,也可能是mysql 异常crash导致relay-log buffer中的数据丢失.那么这时候就需要重设主从同步了.

master log 与relay log的关系的更多相关文章

  1. mysql relay log参数汇总

    前言:MySQL进行主主复制或主从复制的时候会在配置文件制定的目录下面产生相应的relay log,本文档总结这些相关参数的定义及解释. 1.什么是relay log The relay log, l ...

  2. 恢复误删除表黑科技之relay log大法

      Preface       In my previous blogs,I've demonstrated several mothods of how to rescue a dropped ta ...

  3. mysql 主从关系ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository

    连接 amoeba-mysql出现Could not create a validated object, cause: ValidateObject failed mysql> start s ...

  4. MySQL 主从延迟几万秒 Queueing master event to the relay log(转)

    数据库版本Server version:    5.6.24-log Source distribution 问题描述 数据采集平台业务数据库由于批量灌数据导致主从延迟上万秒. 复制线程长期处于Que ...

  5. Slave SQL_THREAD如何重放Relay log

    复制的介绍: 根据日志定义的模式不一样,可以分为:Statement(SBR)模式,Row(RBR)格式或者是MIXED格式,记录最小的单位是一个Event,binlog日志前4个字节是一个magic ...

  6. 关于Relay Log无法自动删除的问题

    本文介绍了一次运维实践中relay-log长期无法自动删除的原因和解决过程 背景: 今天在运维一个mysql实例时,发现其数据目录下的relay-log 长期没有删除,已经堆积了几十个relay-lo ...

  7. MySQL中redo log、undo log、binlog关系以及区别

    MySQL中redo log.undo log.binlog关系以及区别 本文转载自:MySQL中的重做日志(redo log),回滚日志(undo log),以及二进制日志(binlog)的简单总结 ...

  8. ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository

    salve复制线程停止,尝试start slave 时报ERROR 1872错误mysql> system perror 1872 MySQL error code 1872 (ER_SLAVE ...

  9. Relay log read failure

    root@localhost > show slave status\G*************************** 1. row ************************** ...

随机推荐

  1. python实现简单的循环购物车小功能

    python实现简单的循环购物车小功能 # -*- coding: utf-8 -*- __author__ = 'hujianli' shopping = [ ("iphone6s&quo ...

  2. Hibernate错误:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

    报错:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execu ...

  3. java for循环

    publicclass Test2 {     staticboolean foo(char c) {        System.out.print(c);        returntrue;   ...

  4. Jenkins迁移job

    说明:从一个Jenkins服务器A将现有job迁移到另外一个Jenkins服务器B. 方法:You can copy or move build jobs between instances of p ...

  5. 【Vue】详解Vue生命周期

    Vue实例的生命周期全过程(图) (这里的红边圆角矩形内的都是对应的Vue实例的钩子函数) 在beforeCreate和created钩子函数间的生命周期 在beforeCreate和created之 ...

  6. Iterator、for..of,for...in和自定义遍历器**

    Iterator.for..of,for...in和自定义遍历器 Iterator: var arr = [1,2,3,4,5]; var ite = arr[Symbol.iterator](); ...

  7. Git操作大全[实际用到的都放在这里总结]

    1.如何合并远程两个分支feature-rebuild和develop? g fetch g checkout -b develop origin/develop g merge feature-re ...

  8. ionic2+Angular ionScroll页面滑动监听

    第一:需要在组件中引入相关模块: 第二:如果只是监听页面滑动,只需要标注@ViewChild(Content) content: Content;就可以了. 附加:如果要监听页面的某个元素,并对其进行 ...

  9. swift 3.0 基础练习 面向对象 类的扩展

    要求 为NSString类添加split功能 为NSString类添加一个函数func split(splitStr: NSString)-> [NSString],split是把字符串以特定的 ...

  10. 【php】php 连接数据库

    $mysql_server_name=""; //数据库服务器名称 $mysql_username=""; // 连接数据库用户名 $mysql_passwor ...