传统模式(binlog+position)的复制切换到GTID复制
传统模式(binlog+position)的复制切换到GTID复制:
1)主库和从库上修改参数enforce_gtid_consistency=warn,然后观察error log,确认没有GTID不兼容的语句。
mysql> set @@global.enforce_gtid_consistency=warn;
Query OK, 0 rows affected (0.12 sec)
enforce_gtid_consistency:
Scope:Global
Dynamic:Yes(>= 5.7.6) No(<= 5.7.5)
Type:Enumeration(>= 5.7.6) Boolean(<= 5.7.5)
Default Value:OFF(>= 5.7.6) false(<= 5.7.5)
Valid Values OFF\ON\WARN
Depending on the value of this variable, the server enforces GTID consistency by allowing execution of only statements that can be safely logged using a GTID. You must set this variable to ON before enabling GTID based replication.
The values that enforce_gtid_consistency can be configured to are:
OFF: all transactions are allowed to violate GTID consistency.
ON: no transaction is allowed to violate GTID consistency.
WARN: all transactions are allowed to violate GTID consistency, but a warning is generated in this case. WARN was added in MySQL 5.7.6.
以下语法GTID都不支持:
1.CREATE TABLE ...SELECT ..
该语句会被拆分为create table和insert table两个事务且分配同一个GTID,传到备库后,insert操作会被忽略
ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
2.在事务内部的CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE
ERROR 1787 (HY000): Statement violates GTID consistency:CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE can only be executed outside transactional context.
These statements are also not allowed in a function or trigger because functions and triggers are also considered to be multi-statement transactions.
3.在一个事务内部同时更新非事务引擎表和事务引擎表
ERROR 1785 (HY000): When @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1, updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions,and never in the same statement as updates to transactional tables.
2)主库和从库上修改参数enforce_gtid_consistency=on(记得修改my.cnf配置文件)
mysql> set @@global.enforce_gtid_consistency=on;
Query OK, 0 rows affected (0.00 sec)
3)主库和从库上同时修改参数gtid_mode,顺序为OFF-->OFF_PERMISSIVE-->ON_PERMISSIVE-->ON(记得修改my.cnf配置文件)
mysql> set @@global.gtid_mode = on_permissive;
ERROR 1788 (HY000): The value of @@GLOBAL.GTID_MODE can only be changed one step at a time: OFF <-> OFF_PERMISSIVE <-> ON_PERMISSIVE <-> ON. Also note that this value must be stepped up or down simultaneously on all servers. See the Manual for instructions.
mysql> set @@global.gtid_mode = off_permissive;
Query OK, 0 rows affected (0.30 sec)
mysql> set @@global.gtid_mode = on_permissive;
Query OK, 0 rows affected (0.01 sec)
mysql> set @@global.gtid_mode = on;
Query OK, 0 rows affected (0.14 sec)
4)查看从库延迟,确认无等待事务
mysql> show global status like '%ongoing_anonymous%';
+-------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------+-------+
| Ongoing_anonymous_transaction_count | 0 |
+-------------------------------------+-------+
1 row in set (0.11 sec)
5)从库修改复制模式
1.stop slave;
2.change master to master_auto_position=1;
3.start slave;
6)主从同步验证,特别注意观察主库Executed_Gtid_Set和从库Retrieved_Gtid_Set和Executed_Gtid_Set值的变化
mysql> show master status;
+------------------+----------+---------------------------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+---------------------------------+------------------+------------------------------------------+
| mysql-bin.000037 | 949 | test,testrecovery,testrecovery2 | | 7842c967-0958-11e9-9f6c-000c296ee978:1-3 |
+------------------+----------+---------------------------------+------------------+------------------------------------------+
1 row in set (0.30 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.169.10.241
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000037
Read_Master_Log_Pos: 949
Relay_Log_File: LAPTOP-UC5V1DNQ-relay-bin.000002
Relay_Log_Pos: 1162
Relay_Master_Log_File: mysql-bin.000037
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test,testrecovery,testrecovery2
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: 949
Relay_Log_Space: 1379
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: 10241
Master_UUID: 7842c967-0958-11e9-9f6c-000c296ee978
Master_Info_File: E:\mysql-5.7.24-winx64\data\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: 7842c967-0958-11e9-9f6c-000c296ee978:1-3
Executed_Gtid_Set: 7842c967-0958-11e9-9f6c-000c296ee978:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
————————————————
原文链接:https://blog.csdn.net/u014710633/article/details/93774379