> * GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。
MySQL5.6 在原有主从复制的基础上增加了一个新的复制方式,即基于GTID的复制方式,它由UUID和事务ID两个部分组成,具有如下特点。
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)
参数名 | 含义介绍 |
---|---|
binlog_gtid_simple_recovery | 该参数是控制当MySQL服务重启或启动时候自动寻找GTIDs的值。 |
enforce_gtid_consistency | 该参数是强制要求只允许复制事务安全的事务,请看上面步骤的具体限制。 |
gtid_executed | 已经执行过的GTID信息。 |
gtid_executed_compression_period | 启用GTID时,服务器会定期在mysql.gtid_executed表上执行压缩。通过设置gtid_executed_compression_period系统变量,可以控制压缩表之前允许的事务数,从而控制压缩率。设置为0时,则不进行压缩。 |
gtid_mode | 是否开启GTID模式 |
gtid_next | 表示下一个要执行的GTID信息 |
gtid_owned | 该参数包含全局和session,全局表示所有服务器拥有GTIDs,session级别表示当前client拥有的所有GTIDs。 |
gtid_purged | 已经purge掉的GTIDs,purged掉的GTIDs会包含到gtid_executed中。 |
session_track_gtids | 该参数是控制用于捕获的GTIDs和在OK PACKE返回的跟踪器。 |
# 传统复制
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
参数名 | 含义介绍 |
---|---|
Retrieved_Gtid_Set | Slave节点已经接收到的Master节点的GTIDs |
Executed_Gtid_Set | Slave节点已经执行的GTIDs |
Auto_Position | 自动获取position位置,显示为1 |
GreatSQL是由万里数据库维护的MySQL分支,专注于提升MGR可靠性及性能,支持InnoDB并行查询特性,是适用于金融级应用的MySQL分支版本。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。