设为首页 加入收藏

TOP

MySQL 5.7传统复制到GTID复制的在线切换
2016-12-12 08:15:13 】 浏览:2430
Tags:MySQL 5.7 传统 复制 GTID 在线 切换

要求MySQL 5.7.6及以后版本。
所有组中成员gtid_mode 为off状态。


一.基本环境
主库1: 10.24.65.30 3306 mysql 5.7.14
主库2: 10.24.65.30 3307 mysql 5.7.14
从库:10.24.65.33 3306 mysql 5.7.14
基于binlog+position的传统复制


二.在线切换


1.所有的Server执行
set @@global.enforce_gtid_consistency = warn;


特别注意: 这一步是关建的一步使用不能出现警告。


2.所有的server上执行
set @@global.enforce_gtid_consistency = on;


3.所有的Server上执行(不关心最先最后,但要执行完)
set @@global.gtid_mode = off_permissive;
执行:
set @@global.gtid_mode=on_permissive;
实质在这一步骤生的日志都是带GTID的日志了,这个步骤号称是不关心任何节点,但从实管理上推荐在slave上先执行,然后再去master上执行。


4.传统的binlog复制完成确认
确认传统的binlog复制完毕,该值为0
show status like 'ongoing_anonymous_transaction_count';
需要所有的节点都确认为0.
所有的节点也可以执行一下: flush logs; 用于切换一下日志。


5. 所有的节点启用gtid_mode
set @@global.gtid_mode=on;


6.配置文件修改
把gtid_mode = on相关配置写入配置文件
gtid_mode=on
enforce_gtid_consistency=on


7.启用Gtid的自动查找节点复制
stop slave for channel 'master-65303306';
change master to master_auto_position=1 for channel 'master-65303306';
start slave for channel 'master-65303306'


stop slave for channel 'master-65303307';
change master to master_auto_position=1 for channel 'master-65303307';
start slave for channel 'master-65303307';



三.验证更改
master1执行:
(product)root@localhost [mdb1]> insert into mdb1.t1 select 2;
查看slave channel 'master-65303306'的变化 :
插入数据前:
Relay_Master_Log_File: mysql-bin.000442
Exec_Master_Log_Pos: 234
Executed_Gtid_Set: 58abaa9b-73dd-11e6-9690-0050568a704b:1-16,
ebdca3fd-6eb7-11e6-b20c-0050568a704b:1-32459,
ebdca3fd-6eb7-11e6-b20c-0050568a704c:1-2
插入数据后:
Relay_Master_Log_File: mysql-bin.000442
Exec_Master_Log_Pos: 539
Executed_Gtid_Set: 58abaa9b-73dd-11e6-9690-0050568a704b:1-17,
ebdca3fd-6eb7-11e6-b20c-0050568a704b:1-32459,
ebdca3fd-6eb7-11e6-b20c-0050568a704c:1-2


master2执行:
(product)root@localhost [mdb2]> insert into mdb2.t2 select 2;
插入数据前:
Relay_Master_Log_File: mysql-bin.000191
Exec_Master_Log_Pos: 194
Executed_Gtid_Set: 58abaa9b-73dd-11e6-9690-0050568a704b:1-17,
ebdca3fd-6eb7-11e6-b20c-0050568a704b:1-32459,
ebdca3fd-6eb7-11e6-b20c-0050568a704c:1-2
插入数据后:
Relay_Master_Log_File: mysql-bin.000191
Exec_Master_Log_Pos: 499
Executed_Gtid_Set: 58abaa9b-73dd-11e6-9690-0050568a704b:1-17,
ebdca3fd-6eb7-11e6-b20c-0050568a704b:1-32459,
ebdca3fd-6eb7-11e6-b20c-0050568a704c:1-3


上面的GTID和pos位点都有变化,说明已转换成GTID复制生效。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MySQL 5.7 GTID复制到传统复制在.. 下一篇MySQL 5.7多源复制及并行复制功能

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目