五.如何跳过一个GTID

环境见系列一

5.1 创建表,模拟数据

#主机上
create table t_test (id int primary key ,name varchar(10)); insert into t_test values(1,'aa'),(2,'bb'),(3,'cc'); #备机上插入一条,模拟冲突
insert into t_test values(4,'dd');

5.2 模拟冲突

#主机上
insert into t_test values(4,'dd'); #备机上查看复制状态
show slave status \G;

5.3 通过上图,可以定位到冲突的位置,mysqlbinlog查看具体的语句

#主库上mysqlbinlog 查看相关语句
mysqlbinlog --start-position=930 --stop-position=1193 -d test --base64-output=DECODE-ROWS -v /MySQL/my3306/log/binlog/binlog.000018

5.4 基于GTID模式的复制,跳过一个事务,需要利用一个空事务。

stop slave;
set GTID_NEXT='9760cb92-693e-11e8-85bf-000c29b55cf0:11'; #开启一个空事务
begin;commit; SET GTID_NEXT='AUTOMATIC';
start slave ; #查看复制是否正常
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.144
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000019
Read_Master_Log_Pos: 194
Relay_Log_File: relaylog.000017
Relay_Log_Pos: 357
Relay_Master_Log_File: binlog.000019
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 194
Relay_Log_Space: 804
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 101
Master_UUID: 9760cb92-693e-11e8-85bf-000c29b55cf0
Master_Info_File: /MySQL/my3306/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 9760cb92-693e-11e8-85bf-000c29b55cf0:8-11
Executed_Gtid_Set: 790ff8a6-918a-11e8-87db-000c29c27768:1,
9760cb92-693e-11e8-85bf-000c29b55cf0:1-11
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)

六.利用GTID模式快速改变主从复制关系

原架构:主:192.168.2.144

从:192.168.2.138/192.168.2.147

先架构:改为级联模式

基于GTID复制,DBA可以快速调整复制的拓扑结构,只需要调整复制节点的基本信息,不需要手动寻找复制点

6.1 停止192.168.2.147实例的复制

STOP SLAVE;

6.2 调整192.168.2.147实例的复制关系,修改复制源为138,MASTER_AUTO_POSITION为1

CHANGE MASTER TO MASTER_HOST='192.168.2.138',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;

6.3 启动192.168.2.147

START SLAVE;

6.4 观察复制的情况

SHOW SLAVE STATUS \G;

6.5 START SLAVE后,节点138 与节点 147的交互如下

1.147节点向138节点发起一个Dump Binlg请求,并将自身已经执行的GTID集合信息一起发送给138节点。
2.138节点通过对比接收到147节点发送过来的GTID集合,将147节点未执行的Binlog信息发送给C节点。
3.147节点获取未执行的Binlog信息,并应用这些Binlog,在这个过程中,138节点还会不断的发送最新的Binlog到147.
4.147节点不断的apply Binlog,最终实现147节点与138节点的同步。

正常来说,到这一步级联复制就建立起来了,但是由于本文之前在192.168.2.138上跳过一个GTID,导致报错

解决方案:

RESET MASTER;  

#在 192.168.2.138上 查询Executed_Gtid_Set
show MASTER status \G;
*************************** 1. row ***************************
File: binlog.000007
Position: 1385
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 790ff8a6-918a-11e8-87db-000c29c27768:1,
9760cb92-693e-11e8-85bf-000c29b55cf0:1-11
1 row in set (0.00 sec) #在192.168.2.147跳过这些GTID
SET GLOBAL GTID_PURGED='9760cb92-693e-11e8-85bf-000c29b55cf0:1-11';
START SLAVE; #此时复制正常
show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.138
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000007
Read_Master_Log_Pos: 1385
Relay_Log_File: relaylog.000003
Relay_Log_Pos: 445
Relay_Master_Log_File: binlog.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1385
Relay_Log_Space: 1203
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 102
Master_UUID: 790ff8a6-918a-11e8-87db-000c29c27768
Master_Info_File: /MySQL/my3306/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 790ff8a6-918a-11e8-87db-000c29c27768:1
Executed_Gtid_Set: 9760cb92-693e-11e8-85bf-000c29b55cf0:1-11
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)

MySQL GTID (三)的更多相关文章

  1. MySQL GTID 错误处理汇总

    MySQL GTID是在传统的mysql主从复制的基础之上演化而来的产物,即通过UUID加上事务ID的方式来确保每一个事物的唯一性.这样的操作方式使得我们不再需要关心所谓的log_file和log_P ...

  2. MySQL GTID (二)

    MySQL GTID 系列之二 三.在线将GTID转化为传统模式 环境见上篇系列文章 关闭GTID,不用停止服务,不影响线上业务 3.1 关闭GTID复制,调整为传统复制 #SLVAE实例上停止复制 ...

  3. MySQL GTID (一)

    MySQL GTID 系列之一 一.GTID相关概念 GTID:全局事务标识符,MySQL5.6版本开始在主从复制中推出的重量级特性. 每提交一个事务,当前执行线程都会拿到一个给定复制环境中唯一的GT ...

  4. PHP的学习--连接MySQL的三种方式

    记录一下PHP连接MySQL的三种方式. 先mock一下数据,可以执行一下sql. /*创建数据库*/ CREATE DATABASE IF NOT EXISTS `test`; /*选择数据库*/ ...

  5. (转载)MySQL默认INFORMATION_SCHEMA,MySQL,TEST三个数据库用途

    (转载)http://www.45it.com/database/201204/29390.htm 本文简要说明了MySQL数据库安装好后自带的INFORMATION_SCHEMA,MySQL,TES ...

  6. MySQL默认INFORMATION_SCHEMA,MySQL,TEST三个数据库用途

    本文简要说明了MySQL数据库安装好后自带的INFORMATION_SCHEMA,MySQL,TEST三个数据库的用途. 第一个数据库INFORMATION_SCHEMA:提供了访问数据库元数据的方式 ...

  7. MySQL优化三(InnoDB优化)

    body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-top: 10 ...

  8. 使用zabbix监控mysql的三种方式

    使用zabbix监控mysql的三种方式 1.只是安装agent 2.启用模板监控 3.启用自定义脚本的模板监控 zabbix中默认有mysql的监控模板.默认已经在zabbix2.2及以上的版本中. ...

  9. php 链接mysql的三种方式对比

    PHP连接Mysql的三种方式: 1.原生的连接方式  原生的连接方式是面向过程的写法 <?php $host = 'localhost'; $database = 'test'; $usern ...

随机推荐

  1. 003——数组(三)count()reset()end()prev()next()current()

    <?php /** * count 统计数组中元素的个数 */ /*$arr=array('blog.com','博客论坛',array('php课程','css课程')); echo coun ...

  2. POJ 3414 dfs 回溯

    题目链接:http://poj.org/problem?id=3414 题意:三个值A, B, C, A和B是两个杯子的容量,问最短操作数使A或者B里的水量是C.有三种操作. 思路:dfs.暴力 很简 ...

  3. mysqlbinlog初识

    mysql-binlog->解析mysql的binlog日志 mysql的binlog日志是什么? 数据目录下的日下文件就是mysql的binlog日志 mysql-bin.00001 mysq ...

  4. win32程序应用mfc库

    引入<afx.h> 此时会出现如下错误: #ifdef _DLL#ifndef _AFXDLL#error Building MFC application with /MD[d] (CR ...

  5. python 发送QQ邮件的小例子

    首先QQ邮件用第三方客户端发送要申请验证码.而不是QQ的密码. 授权码就是你接下来登录要使用的密码 那么剩下的工作就很简单了.附简单代码如下: #coding:utf-8 import smtplib ...

  6. 【LeetCode 1_数组_哈希表】Two Sum

    解法一:O(N) vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, i ...

  7. oracle创建定时器详解|interval属性

    定时任务首先先创建定时任务中的存储过程 create or replace procedure pro_jggl as                                          ...

  8. boost 中文编码转换

    Lstring CHanderHttp::CircleDesc(Lint nCurCircle, Lint nMaxCircle,Lint usercount){ std::stringstream ...

  9. 博客(第0次作业)—— New Starting Point

    一.最理想的师生关系是健身教练和学员的关系,在这种关系中你期望获得来自老师的那些帮助? 正如文章中所说,这些学员的想法得足够强烈, 他/她才会花钱去参加这样的健身活动,每一个来学习的学生,  都是想学 ...

  10. JavaScript的this原理

    this原理 理解下面两种写法,可能有不一样的结果. var obj = { foo: function () {} }; var foo = obj.foo; // 写法一 obj.foo() // ...