标签:value position auto gtid_mode bind ted main last ons
1.基本环境:
|
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
|
2.在线切换
1.master和slave执行
mysql>set @@global.enforce_gtid_consistency = warn;
mysql>set @@global.enforce_gtid_consistency = on;
mysql>set @@global.gtid_mode = off_permissive;
mysql> set @@global.gtid_mode=on_permissive;
在这个步骤开始生的日志都带有gtid信息,执行步骤一般推荐在先在slave上执行,然后再去master上执行。
mysql> show status like ‘ongoing_anonymous_transaction_count‘;
+-------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------+-------+
| Ongoing_anonymous_transaction_count | 0 |
+-------------------------------------+-------+
1 row in set (0.00 sec)
所有的节点都确认为0. 查看是不是0,如果是0就都是gtid复制
5.所有的节点也可以执行一下: flush logs; 用于切换一下日志。
mysql> flush logs;
6. master和slave都要执行
mysql> set @@global.gtid_mode=on;
7.停止slave端
mysql>stop slave;
mysql> change master to master_auto_position=1;
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.000008
Read_Master_Log_Pos: 194
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000008
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: 608
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-4
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
可以看到 Auto_Position的值为1了
8.插入数据测试
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.000008
Read_Master_Log_Pos: 469
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 642
Relay_Master_Log_File: mysql-bin.000008
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: 883
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:5
Executed_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1-5
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
原来的:
Exec_Master_Log_Pos: 194
Executed_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1-4
现在的:
Exec_Master_Log_Pos: 469
Executed_Gtid_Set: 4dc90770-e120-11e6-9fd7-000c29355816:1-5
可以看到pos和gtid都发生了变化,说明gtid切换已经成功。
执行 flush logs; 命令,看到新产生的GTID值发生变化,说明已经稳定。
8.最后一步记住把修改的参数写入配置文件my.cnf
gtid_mode=on
enforce_gtid_consistency=on
切换-5.7-传统复制切换成GTID复制
标签:value position auto gtid_mode bind ted main last ons
原文地址:http://www.cnblogs.com/liang545621/p/7518348.html