《MysqL入门MysqL5.7不停业务将传统复制变更为GTID复制的实例》要点:
本文介绍了MysqL入门MysqL5.7不停业务将传统复制变更为GTID复制的实例,希望对您有用。如果有疑问,可以联系我们。
由于GTID的优势,我们需要将传统基于file-pos的复制更改为基于GTID的复制,如何在线变更成为我们关心的一个点,如下为具体的方法:MysqL学习
目前我们有一个传统复制下的M-S结构:MysqL学习
port 3301 masterMysqL学习
port 3302 slaveMysqL学习
master上(3301):[zejin] 3301>select * from t_users;+----+------+| ID | name |+----+------+| 1 | hao || 2 | zhou |+----+------+rows in set (0.00 sec) slave上(3302):[zejin] 3302>show slave status\G*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.1.240Master_User: replMaster_Port: 3301Connect_Retry: 60Master_Log_file: binlog57.000002Read_Master_Log_Pos: 417Relay_Log_file: zejin240-relay-bin.000004Relay_Log_Pos: 628Relay_Master_Log_file: binlog57.000002Slave_IO_Running: YesSlave_sql_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_table:Replicate_Ignore_table:Replicate_Wild_Do_table:Replicate_Wild_Ignore_table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 417Relay_Log_Space: 884Until_Condition: NoneUntil_Log_file:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_file:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error:Last_sql_Errno: 0Last_sql_Error:Replicate_Ignore_Server_IDs:Master_Server_ID: 3301Master_UUID: a97983fc-5a29-11e6-9d28-000c29d4dc3fMaster_Info_file: /home/MysqL/I3302/master.infosql_Delay: 0sql_Remaining_Delay: NulLSlave_sql_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind:Last_IO_Error_Timestamp:Last_sql_Error_Timestamp:Master_SSL_Crl:Master_SSL_Crlpath:RetrIEved_GtID_Set:Executed_GtID_Set:auto_position: 0Replicate_Rewrite_DB:Channel_name:Master_TLS_Version:row in set (0.00 sec) [zejin] 3302>select * from t_users;+----+------+| ID | name |+----+------+| 1 | hao || 2 | zhou |+----+------+rows in set (0.00 sec)
如下为在线变更的具体的 *** 作步骤:MysqL学习
前提:MysqL学习
1.要求所有的MysqL版本5.7.6或更高的版本.
MysqL学习
2.目前拓扑结构中所有的MysqL的gtID_mode的值为off状态.
MysqL学习
3.如下的 *** 作步骤都是有序的,不要跳跃着进行.
MysqL学习
补充一下全局系统变量GTID_MODE变量值说明: MysqL学习
OFF 新事务是非GTID, Slave只接受不带GTID的事务,传送来GTID的事务会报错MysqL学习
OFF_PERMISSIVE 新事务是非GTID, Slave即接受不带GTID的事务也接受带GTID的事务MysqL学习
ON_PERMISSIVE 新事务是GTID, Slave即接受不带GTID的事务也接受带GTID的事务MysqL学习
ON 新事务是GTID, Slave只接受带GTID的事务MysqL学习
需要注意的是,这几个值的改变是有顺序的,即MysqL学习
off<--->OFF_PERMISSIVE<--->ON_PERMISSIVE<--->ONMysqL学习
不能跳跃执行,会报错.MysqL学习
step1:在每个MysqL实例上,将ENFORCE_GTID_CONSISTENCY设置为warning,哪台先执行不影响结果.MysqL学习
[zejin] 3302>set @@global.enforce_gtID_consistency=warn;query OK,0 rows affected (0.00 sec)[zejin] 3301>set @@global.enforce_gtID_consistency=warn;query OK,0 rows affected (0.00 sec)
注意:执行完这条语句后,如果出现GTID不兼容的语句用法,在错误日志会记录相关信息,那么需要调整应该程序避免不兼容的写法,直到完全没有产生不兼容的语句,可以通过应该程序去排查所有的sql,也可以设置后观察错误日志一段时间,这一步非常重要. MysqL学习
step2:在每个MysqL实例上,设置ENFORCE_GTID_CONSISTENCY为ON,哪台先执行不影响结果MysqL学习
在第一步完成后,就可以将值设置为on.MysqL学习
[zejin] 3301>set @@global.enforce_gtID_consistency=on;query OK,0 rows affected (0.03 sec) [zejin] 3302>set @@global.enforce_gtID_consistency=on;query OK,0 rows affected (0.00 sec)
step3:在每个MysqL实例上,设置GTID_MODE为off_permissiv;哪台先执行不影响结果MysqL学习
[zejin] 3301>SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;query OK,0 rows affected (0.00 sec) [zejin] 3302>SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;query OK,0 rows affected (0.00 sec)
step4:在每个MysqL实例上,设置GTID_MODE为on_permissiv;;哪台先执行不影响结果MysqL学习
[zejin] 3302>SET @@GLOBAL.GTID_MODE = on_permissive;query OK,0 rows affected (0.00 sec)[zejin] 3301>SET @@GLOBAL.GTID_MODE = on_permissive;query OK,0 rows affected (0.01 sec)
step5:在每个MysqL实例上检查变量ONGOING_ANONYMOUS_TRANSACTION_COUNTMysqL学习
[zejin] 3301>SHOW STATUS liKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';+-------------------------------------+-------+| Variable_name | Value |+-------------------------------------+-------+| Ongoing_anonymous_transaction_count | 0 |+-------------------------------------+-------+row in set (0.02 sec) [zejin] 3302>SHOW STATUS liKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';+-------------------------------------+-------+| Variable_name | Value |+-------------------------------------+-------+| Ongoing_anonymous_transaction_count | 0 |+-------------------------------------+-------+row in set (0.02 sec)
需要等到此变量为0MysqL学习
step6: 确保所有的匿名事务(非GTID事务)已经被完全复制到所有的server上.MysqL学习
检查方法:MysqL学习
在master上:[zejin] 3301>show master status;+-----------------+----------+--------------+------------------+-------------------+| file | position | binlog_Do_DB | binlog_Ignore_DB | Executed_GtID_Set |+-----------------+----------+--------------+------------------+-------------------+| binlog57.000005 | 154 | | | |+-----------------+----------+--------------+------------------+-------------------+row in set (0.00 sec) 在slave上,[zejin] 3302>show slave status\G*************************** 1. row ***************************…… Relay_Master_Log_file: binlog57.000005 Exec_Master_Log_Pos: 154……
检查这两项Relay_Master_Log_file的值大于binlog57.000005,MysqL学习
或者等于Relay_Master_Log_file等于binlog57.000005并且Exec_Master_Log_Pos的值大于等于154即可 MysqL学习
或者slave直接用函数:MysqL学习
[zejin] 3302>SELECT MASTER_POS_WAIT('binlog57.000005',154);+-----------------------------------------+| MASTER_POS_WAIT('binlog57.000005',154) |+-----------------------------------------+| 0 |+-----------------------------------------+row in set (0.00 sec)
返回结果大于等于0就说明匿名事务已经全部复制完成 MysqL学习
step7: 确认整个拓扑结构中已经没有匿名事务的存在,如之前产生的所有匿名事务已经全部被执行完毕,甚至二进制日志中也不要有匿名事务,可以通过flush logs,并让MysqL来自动清理旧的二进制日志文件. MysqL学习
step8: 在每个MysqL实例上,设置GTID_MODE为on,MysqL学习
[zejin] 3301>SET @@GLOBAL.GTID_MODE = ON;query OK,0 rows affected (0.04 sec) [zejin] 3302>SET @@GLOBAL.GTID_MODE = ON;query OK,0 rows affected (0.04 sec)
step9: 在每个MysqL实例的配置文件my.cnf上,增加gtID-mode=ONMysqL学习
验证:MysqL学习
[zejin] 3301>insert into t_users values(3,'chen');query OK,1 row affected (0.02 sec)[zejin] 3301>update t_users set name='li' where ID=1;query OK,1 row affected (0.03 sec)Rows matched: 1 Changed: 1 Warnings: 0[zejin] 3301>select * from t_users;+----+------+| ID | name |+----+------+| 1 | li || 2 | zhou || 3 | chen |+----+------+rows in set (0.00 sec) [zejin] 3302>show slave status\G*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.240 Master_User: repl Master_Port: 3301 Connect_Retry: 60 Master_Log_file: binlog57.000006 Read_Master_Log_Pos: 462 Relay_Log_file: zejin240-relay-bin.000012 Relay_Log_Pos: 673 Relay_Master_Log_file: binlog57.000006 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: 462 Relay_Log_Space: 969 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: 0Master_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: 3301 Master_UUID: a97983fc-5a29-11e6-9d28-000c29d4dc3f Master_Info_file: /home/MysqL/I3302/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: a97983fc-5a29-11e6-9d28-000c29d4dc3f:1-2 Executed_GtID_Set: a97983fc-5a29-11e6-9d28-000c29d4dc3f:1-2 auto_position: 0 Replicate_Rewrite_DB: Channel_name: Master_TLS_Version: row in set (0.00 sec)
至此完成从传统复制到GTID复制的在线转换.MysqL学习
以上这篇MysqL5.7不停业务将传统复制变更为GTID复制的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持内存溢出PHP.MysqL学习
总结以上是内存溢出为你收集整理的Mysql入门MySQL5.7不停业务将传统复制变更为GTID复制的实例全部内容,希望文章能够帮你解决Mysql入门MySQL5.7不停业务将传统复制变更为GTID复制的实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)