这篇文章主要为大家展示了“MySQL 5.7如何使用GTID方式搭建复制环境”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“MySQL 5.7如何使用GTID方式搭建复制环境”这篇文章吧。
当使用GTIDs(global transaction identifiers),每个事务在提交时,都会被标记一个独特的事务号,被用于在备库上应用,这样在搭建复制环境时,不用使用日志文件和日志位置的传统方式搭建,大大简化了复制环境的搭建流程。可以使用语句级别和行级别的复制格式,建议使用行级别的复制格式。
GTID的格式如下
GTID = source_id:transaction_id
source_id代表源服务端,transaction_id代表事务的顺序号。
限制:
因为以GTID为基础的复制时基于事务的,一些特性在复制中会有限制。
不支持非事务性的表,如MyISAM表等。
不支持CREATE TABLE … SELECT语句。CREATE TABLE … SELECT对于语句级别的复制格式不安全。当使用行级别的复制格式时,这个语句在日志中被记录成两个单独的事件,一个是表的创建,另一个是表的插入操作。当这个语句在一个事务中被执行时,在某些情况下这两个事件会被分配相同的事务号,这样第2个执行插入操作的事务可能会被从库跳过。
临时表。在事务内部,GTID复制不支持CREATE TEMPORARY TABLE、DROP TEMPORARY TABLE语句。
GTID复制不支持sql_slave_skip_counter参数。如果需要跳过事务,使用主库上的gtid_executed参数。
主库gtid_purged参数包含了所有在主库二进制日志中清除的所有事务。
搭建流程:
编辑主库的配置文件,并重启主库
# Log
server-id = 27100
log-bin = production-bin
#log-bin-index = /log/production-bin.index
binlog_format = row
log_slave_updates
gtid-mode = ON
enforce-gtid-consistency = ON
编辑从库的配置文件,并重启从库
# Log
server-id = 35100
log-bin = production-bin
#log-bin-index = /log/production-bin.index
binlog_format = row
log_slave_updates
gtid-mode = ON
enforce-gtid-consistency = ON
–启动IO和SQL线程
mysql> start slave;
Query OK, 0 rows affected (0.04 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.78.141
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: production-bin.000002
Read_Master_Log_Pos: 448
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 671
Relay_Master_Log_File: production-bin.000002
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: 448
Relay_Log_Space: 882
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: 27100
Master_UUID: cf291e84-2c89-11e6-b6f0-000c29631605
Master_Info_File: /var/lib/mysql/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: cf291e84-2c89-11e6-b6f0-000c29631605:1
Executed_Gtid_Set: cf291e84-2c89-11e6-b6f0-000c29631605:1
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
mysql> show processlist;
+—-+————-+———–+——+———+——+——————————————————–+——————+
| Id | User | Host | db | Command | Time | State | Info |
+—-+————-+———–+——+———+——+——————————————————–+——————+
| 4 | root | localhost | fire | Query | 0 | starting | show processlist |
| 6 | system user | | NULL | Connect | 480 | Waiting for master to send event | NULL |
| 7 | system user | | NULL | Connect | 153 | Slave has read all relay log; waiting for more updates | NULL |
+—-+————-+———–+——+———+——+——————————————————–+——————+
3 rows in set (0.02 sec)
以上是“MySQL 5.7如何使用GTID方式搭建复制环境”这篇文章的所有内容,感谢各位的阅读!
MySQL 5.7如何使用GTID方式创建复制环境
这篇文章主要为大家展示了MySQL 5.7如何使用GTID方式搭建复制环境,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下MySQL 5.7如何使用GTID方式搭建复制环境这篇文章吧。 当使用GTIDs(global transaction identif
本文来自网络,不代表站长网立场,转载请注明出处:https://www.tzzz.com.cn/html/jc/mysql/2021/1226/43500.html