千家信息网

说GTID - Auto-Positioning

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,GTID-based的复制,在初始化阶段,Slave节点会把已接收到的和提交的GTID集合信息,发送给Master节点。该GTID集合等价于后面两个GTID集合的并集,@@GLOBAL.gtid_ex
千家信息网最后更新 2026年11月03日说GTID - Auto-Positioning

GTID-based的复制,在初始化阶段,Slave节点会把已接收到的和提交的GTID集合信息,发送给Master节点。该GTID集合等价于后面两个GTID集合的并集,@@GLOBAL.gtid_executed + performance_schema.replication_connection_status.RECEIVED_TRANSACTION_SET。


Master节点通过对比Slave节点发送过来的GTID集合信息,然后把所有记录在现存二进制日志文件中的,没有在Slave节点上执行过的GTID集合,发送给Slave节点。



那么,Master节点是如何对比Slave节点发送过来的GTID集合信息的呢?


Master节点会按照自己有的UUID为准,将GTID集合分类,分别计算同类GTID集合的差集。此环节,若Master节点发现Slave节点发送过来的GTID集合中UUID的种类,比自身上UUID的种类多,Master节点会忽略该情况,复制逻辑还会继续进行。


实际例子如下,此情况复制是正常的。


Master节点上GTID集合信息:

[root@mysql.sock][db1]> show master status\G

*************************** 1. row ***************************

File: bin.000002

Position: 796

Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set: 0c34233d-b2e1-11e9-85cf-080027f22add:1-2,

4fdc13e1-b59e-11e9-b5e0-080027f22add:1-2

1 row in set (0.01 sec)


Slave节点上GTID集合信息:

[root@mysql.sock][lg]> show master status\G

*************************** 1. row ***************************

File: bin.000004

Position: 832

Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set: 32a0c858-b59f-11e9-b069-0800270c3d91:1-2,

447e96e1-b59f-11e9-95fe-0800270c3d91:1-2,

b8282f18-b59e-11e9-83b0-0800270c3d91:1-5

1 row in set (0.00 sec)


建立复制关系后,Slave节点上集合信息:

[root@mysql.sock][lg]> show master status \G

*************************** 1. row ***************************

File: bin.000004

Position: 1763

Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set: 0c34233d-b2e1-11e9-85cf-080027f22add:1-2,

32a0c858-b59f-11e9-b069-0800270c3d91:1-2,

447e96e1-b59f-11e9-95fe-0800270c3d91:1-2,

4fdc13e1-b59e-11e9-b5e0-080027f22add:1-2,

b8282f18-b59e-11e9-83b0-0800270c3d91:1-5

1 row in set (0.00 sec)



又若Master节点发现Slave节点上相同UUID对应的GTID,比自身上的GTID多,这时Master节点会发送ER_SLAVE_HAS_MORE_GTIDS_THAN_MASTER报错给Slave节点。


实际例子报错如下:


Last_IO_Errno: 1236(MySQL error code 1236 (ER_MASTER_FATAL_ERROR_READING_BINLOG): Got fatal error %d from master when reading data from binary log: '%-.320s')

Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Slave has more GTIDs than the master has, using the master's SERVER_UUID. This may indicate that the end of the binary log was truncated or that the last binary log file was lost, e.g., after a power or disk failure when sync_binlog != 1. The master may or may not have rolled back transactions that were already replica'

Last_SQL_Errno: 0


或Master节点发现计算出来相同UUID的GTID集合的差集中,有GTID已被删除了,这时Master节点会发送ER_MASTER_HAS_PURGED_REQUIRED_GTIDS报错给Slave节点。


实际例子报错如下:


Last_IO_Errno: 1236

Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.'

Last_SQL_Errno: 0



经过上面的逻辑后,Master节点最终得以将Slave节点需要的GTID集合(差集)发送过来,复制就这样开始了。

节点 信息 例子 实际 差集 相同 种类 逻辑 上集 两个 二进制 同类 情况 文件 日志 环节 种类多 等价 阶段 面的 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 中资互联网科技 广州互联网科技公司 互联网科技公司电话 唐信互联网科技 四个字互联网科技公司取名 成都仁贤领冠互联网科技有限公司 深圳市运趣互联网科技有限公司 玖二柒互联网科技公司待遇 宁夏众和广鑫互联网科技有限公司 江阴互联网智能科技产品进口 广州市恰铎互联网科技有限公司 互联网金融科技名词解释 互联网领先科技宣传片 2021世界互联网领先科技成果发布 西安左小互联网科技有限公司 互联网科技品牌 青岛互联网科技园 瑞安市蟠桃会互联网科技有限公司 互联网高科技绘画 小牛互联网科技有限公司地址 科技互联网政务服务 苏州互联网科技贷款公司 海南购全球互联网科技 衡水科技产业互联网平台 卫星互联网科技股票 昭通云南众福互联网科技有限公司 每天都有哪些好的互联网科技 伍佰万互联网科技怎么赚钱 美国互联网科技公司 互联网时代科技型公司的机会
0