Master | Slave | |
MySQL版本 | MySQL-5.7.16-X86_64 | MySQL-5.7.16-X86_64 |
IP | 192.168.56.156 | 192.168.56.157 |
Port | 3306 | 3306 |
切换-5.7-GTID复制切换成传统复制
转载mysql5.7 gtid和传统复制在线切换,5.7.6 之后 不用重启可以直接在线切换
基本环境
gtid_mode 几种状态的说明:
off : 不产生GTID,基于binlog+position ,slave也不能接受GTID的日志
off_permissive : 不产生GTID,但作为slave可以识别到GTID事物,也可以识别非GTID事物
on_permissive : 产生GTID事物,Slave可以处理GTID事物和非GTID事物
on : 产生GTID事物,slave只接受GTID事物
1.停止slave
mysql>stop slave;
2. 查看slave状态,记录master_log_file和position信息。
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.56.156
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 428
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 641
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: No
Slave_SQL_Running: No
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: 428
Relay_Log_Space: 842
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: NULL
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: 1563306
Master_UUID: 4dc90770-e120-11e6-9fd7-000c29355816
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1
Executed_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
3.根据上面记录的信息 change master
change master to master_log_file='mysql-bin.000001',master_log_pos=428,master_auto_position=0;
参数解释:
master_log_file = Relay_Master_Log_File: mysql-bin.000001
master_log_pos = Exec_Master_Log_Pos: 428
master_auto_position=0 禁用: master_auto_position
mysql>start slave;
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.156
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 428
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000001
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: 428
Relay_Log_Space: 561
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: 1563306
Master_UUID: 4dc90770-e120-11e6-9fd7-000c29355816
Master_Info_File: mysql.slave_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:
Executed_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
数据测试
略。
4. 更改gtid模式(master和slave都执行)
4.1 master 和 slave都要修改
mysql> set @@global.gtid_mode=on_permissive;
mysql> show variables like 'gtid_mode';
+---------------+---------------+
| Variable_name | Value |
+---------------+---------------+
| gtid_mode | ON_PERMISSIVE |
+---------------+---------------+
on_permissive 产生GTID事物,Slave可以处理GTID事物和非GTID事物
可以在主库上insert数据,show master查看信息。(步骤略)
4.2 master和slave都要修改
mysql> set @@global.gtid_mode=off_permissive;
mysql> show variables like 'gtid_mode';
+---------------+----------------+
| Variable_name | Value |
+---------------+----------------+
| gtid_mode | OFF_PERMISSIVE |
+---------------+----------------+
off_permissive 不产生GTID,但作为slave可以识别到GTID事物,也可以识别非GTID事物
可以测试一下 insert into 一条数据, show master status;(具体步骤略)
4.3 master和slave端都要修改
mysql>set @@global.gtid_mode=off;
mysql>show variables like 'gtid_mode';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_mode | OFF |
+---------------+-------+
1 row in set (0.01 sec)
OFF : 不产生GTID,基于binlog+position ,slave也不能接受GTID的日志
5.查看更改是否有效
5.1先记录slave的相关信息
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.156
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 194
Relay_Log_File: relay-bin.000008
Relay_Log_Pos: 407
Relay_Master_Log_File: mysql-bin.000004
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: 695
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: 1563306
Master_UUID: 4dc90770-e120-11e6-9fd7-000c29355816
Master_Info_File: mysql.slave_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: 4dc90770-e120-11e6-9fd7-000c29355816:2-4
Executed_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1-4
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
在master做一些数据操作:
略。
如果看到pos的信息变化了,而gtid的信息没有变。说明现在已经转换成了传统复制。
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.156
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 469
Relay_Log_File: relay-bin.000008
Relay_Log_Pos: 682
Relay_Master_Log_File: mysql-bin.000004
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: 469
Relay_Log_Space: 970
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: 1563306
Master_UUID: 4dc90770-e120-11e6-9fd7-000c29355816
Master_Info_File: mysql.slave_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: 4dc90770-e120-11e6-9fd7-000c29355816:2-4
Executed_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1-4
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
6.最后一步:修改配置文件my.conf
[mysqld]
gtid_mode=off
enforce_gtid_consistency=off
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:DG动态性能视图详解
下一篇:5.7-多源复制搭建
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL 组复制搭建
MySQL 组复制搭建
MySQL -
mysql传统复制环境切换成gtid复制
1.目前的环境:master 192.168.26.233 3306 slave 192.168.
mysql传统复制环境切换成gtid复制 mysql f5 SQL -
MySQL5.7 传统复制和GTID复制间的在线互相切换
MySQL5.7 传统复制和GTID复制间的在线互相切换
MySQL GTID 传统复制 事务 主从 -
MySQL传统复制和GTID复制参考
MySQL传统复制和GTID复制参考
MySQL 传统 复制 GTID -
传统主动转换为GTID复制
GTID复制GTID复制又叫全局事物ID(global transaction ID),是一个已提交事物的编号
GTID mysql sql 主从复制 -
Mysql 基于GTID的主从复制及切换
Mysql 基于GTID 主从复制配置、主从切换、主主配置
mysql 主从 gtid 主主复制 -
GTID主从复制转换为传统主从复制
GTID复制转换为传统主从复制切换操作非常简单,可以在线完成。第一步:检查当前
GTID mysql sql 主从复制 -
基于MySQL5.7GTID在线切换
在线切换的版本要>=5.7.6 gitd_mode 解释 OFF ...
配置文件 git mysql