时间:2022-11-21 08:27:03 | 栏目:Mysql | 点击:次
MySQL5.6 在原有主从复制的基础上增加了一个新的复制方式,即基于GTID的复制方式,它由UUID和事务ID两个部分组成,具有如下特点。
position
位置。log_file
和log_Pos
的位置。sql_slave_skip_counte
操作,传统复制可以使用这个命令跳过事务。InnoDB
和MyISAM
。create temporary table 和drop temporary table
语句不支持。master
节点在更新数据的时候,会在事务前产生GTID信息,一同记录到binlog日志中。binlog写
入到本地relay log中。relay log
中读取GTID,设置gtid_next
的值为该gtid,然后对比slave端的binlog
是否有记录。除传统复制需要开启的binlog
相关参数之外,GTID同步需额外开启如下参数设置,注意主从节点需要同步开启。
gtid_mode=on # 开启GTID enforce-gtid-consistency=on # 需要同步设置该参数 log-slave-updates=1 # 5.6 版本需要开启该参数
[root@GreatSQL][(none)]>show variables like '%gtid%'; +----------------------------------+-------------------------------------------------------------------------------------+ | Variable_name | Value | +----------------------------------+-------------------------------------------------------------------------------------+ | binlog_gtid_simple_recovery | ON | | enforce_gtid_consistency | ON | | gtid_executed | 613743f5-8b1c-11ec-9922-00155dcff911:1-14 | | gtid_executed_compression_period | 0 | | gtid_mode | ON | | gtid_next | AUTOMATIC | | gtid_owned | | | gtid_purged | | | session_track_gtids | OFF | +----------------------------------+-------------------------------------------------------------------------------------+ 9 rows in set (0.00 sec)
参数简要说明:
# 传统复制 change master to master_host="127.0.0.1",master_port=3310,MASTER_USER='sync',MASTER_PASSWORD='GreatSQL',MASTER_LOG_FILE='log-bin.000005', MASTER_LOG_POS=4111; # GTID复制 change master to master_host="127.0.0.1",master_port=3310,MASTER_USER='sync',MASTER_PASSWORD='GreatSQL',MASTER_AUTO_POSITION=1
GTID同步在建立复制的时候,将传统复制由人为指定binlog
的pos位点改为了MASTER_AUTO_POSITION=1
自动获取binlog的pos位点。
除了传统的查看binlog和pos值之外,GTID模式可以更直观的查看某个事务执行的情况。
[root@GreatSQL][(none)]>show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.6.215 Master_User: sync Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000001 Read_Master_Log_Pos: 2425 Relay_Log_File: mgr2-relay-bin.000002 Relay_Log_Pos: 2634 Relay_Master_Log_File: binlog.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: 2425 Relay_Log_Space: 2842 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: 2153306 Master_UUID: 613743f5-8b1c-11ec-9922-00155dcff911 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: 613743f5-8b1c-11ec-9922-00155dcff911:1-10 Executed_Gtid_Set: 613743f5-8b1c-11ec-9922-00155dcff911:1-10, 652ade08-8b1c-11ec-9f62-00155dcff90a:1-2 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0 Network_Namespace: 1 row in set, 1 warning (0.01 sec) ERROR: No query specified
GTID相关键参数说明: