您的位置:首页 > 数据库 > MySQL

mysql 5.7传统复制到gtid复制的在线切换

2016-09-10 09:27 651 查看
要求MySQL 5.7.6及以后版本。

所有组中成员gtid_mode 为off状态。

一.基本环境
主库1: 192.168.65.30  3306 mysql 5.7.14

主库2: 192.168.65.30  3307 mysql 5.7.14

从库:192.168.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复制生效。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: