MySQL的Retrieved_Gtid_Set、Executed_Gtid_Set哪里来

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 验证Retrieved_Gtid_Set、Executed_Gtid_Set哪里来 relay_log_recover=0 slave mysql> start slave; shQuery OK, 0 rows affected (0.

验证环境

MySQL 5.7.23 Centos7.4

relay_log_recover=0

验证过程

slave

mysql> start slave;
shQuery OK, 0 rows affected (0.45 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.101
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relaylog.000003
                Relay_Log_Pos: 367
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
...
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
AI 代码解读

master

root@localhost : (none):12: > create database hjj;
Query OK, 1 row affected (0.00 sec)

root@localhost : (none):12: > use hjj
Database changed
root@localhost : hjj:12: > source /root/net_test_1.sql;

root@localhost : hjj:13: > show master status\G
*************************** 1. row ***************************
             File: mysql-bin.000001
         Position: 39126486
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 376a65d8-ec05-11e8-becd-080027f2f9fd:1-202
1 row in set (0.00 sec)
AI 代码解读

slave

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.101
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 39126486
               Relay_Log_File: relaylog.000003
                Relay_Log_Pos: 39126699
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
...
           Retrieved_Gtid_Set: 376a65d8-ec05-11e8-becd-080027f2f9fd:1-202
            Executed_Gtid_Set: 376a65d8-ec05-11e8-becd-080027f2f9fd:1-202
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.14 sec)
AI 代码解读

master

root@localhost : hjj:13: > source /root/net_test.sql; 
AI 代码解读

slave

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.101
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 78197987
               Relay_Log_File: relaylog.000004
                Relay_Log_Pos: 39071814
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
...
           Retrieved_Gtid_Set: 376a65d8-ec05-11e8-becd-080027f2f9fd:1-208
            Executed_Gtid_Set: 376a65d8-ec05-11e8-becd-080027f2f9fd:1-208
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

[root@yuelei3 log]# ps -ef|grep mysqld

[root@yuelei3 log]# kill -9 9065 7612
[1]+ Killed /opt/mysql5.7/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf

[root@yuelei3 log]# ls
error.log mysql-bin.000001 mysql-bin.000002 mysql-bin.index relaylog.000003 relaylog.000004 relaylog.index slow-query.log

[root@yuelei3 log]# rm relaylog.000004 
rm: remove regular file ‘relaylog.000004’? y

[root@yuelei3 log]# /opt/mysql5.7/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf &         

[root@yuelei3 log]# /opt/mysql5.7/bin/mysql -uroot -S /data/mysql/run/mysql.sock                    

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.101
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 78197987
               Relay_Log_File: relaylog.000005
                Relay_Log_Pos: 454
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
...
           Retrieved_Gtid_Set: 376a65d8-ec05-11e8-becd-080027f2f9fd:1-202
            Executed_Gtid_Set: 376a65d8-ec05-11e8-becd-080027f2f9fd:1-208
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
AI 代码解读

验证binlog有关GTID

slave

mysql> show master status;
+------------------+----------+--------------+------------------+--------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+--------------------------------------------+
| mysql-bin.000003 | 194 | | | 376a65d8-ec05-11e8-becd-080027f2f9fd:1-208 |
+------------------+----------+--------------+------------------+--------------------------------------------+
1 row in set (0.12 sec)

[root@yuelei3 log]# ps -ef|grep mysqld

[root@yuelei3 log]# kill -9 11778 10325
[1]+ Killed /opt/mysql5.7/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf

[root@yuelei3 log]# ls
error.log mysql-bin.000001 mysql-bin.000002 mysql-bin.000003 mysql-bin.index relaylog.000004 relaylog.000005 relaylog.index slow-query.log

[root@yuelei3 log]# rm mysql-bin.000003 
rm: remove regular file ‘mysql-bin.000003’? y

[root@yuelei3 log]# vim mysql-bin.index 

[root@yuelei3 log]# /opt/mysql5.7/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf &

[root@yuelei3 log]# /opt/mysql5.7/bin/mysql -uroot -S /data/mysql/run/mysql.sock

mysql> show master status;
+------------------+----------+--------------+------------------+--------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+--------------------------------------------+
| mysql-bin.000003 | 194 | | | 376a65d8-ec05-11e8-becd-080027f2f9fd:1-208 |
+------------------+----------+--------------+------------------+--------------------------------------------+
1 row in set (0.00 sec)
AI 代码解读

总结

relay_log_recover=0

  • slave会扫描最后一个relay log文件,Retrieved_Gtid_Set显示的是当前扫描所得的GTID;io线程会通过扫描所得的最后一个GTID+1(如果Retrieved_Gtid_Set>=Executed_Gtid_Set)为依据来拉取,如果Retrieved_Gtid_Set

relay_log_recover=1

  • slave中把所有relay log清除,io线程通过Executed_Gtid_Set后的+1个事务开始拉取并生成新的relay log文件;SQL线程在清除relay log时把Relay_Log_File、Relay_Log_Pos设为空,所以SQL线程从新的relay log文件的第一个事务开始应用
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
MySQL 中character_set_server 和collation_server
在MySQL中,`character_set_server` 和 `collation_server` 是两个重要的系统变量,它们分别用于定义服务器级别的字符集和排序规则。 1. **character_set_server**: * 这个变量定义了MySQL服务器使用的默认字符集。字符集是一组字符的编码方式,它决定了如何在数据库中存储和检索字符数据。 * 例如,`utf8` 是一个常用的字符集,它支持大部分Unicode字符,包括中文、英文、阿拉伯文等。 * 你可以通过以下SQL命令查看当前的 `character_set_server` 设置: ``` sql`SHOW V
1671 1
MySQL中利用FIND_IN_SET进行包含查询的技巧
`FIND_IN_SET`提供了一种简便的方法来执行包含查询,尤其是当数据以逗号分隔的字符串形式存储时。虽然这个方法的性能可能不如使用专门的关系表,但在某些场景下,它提供了快速简便的解决方案。开发者应该根据具体的应用场景和性能要求,权衡其使用。
205 0
mysql中find_in_set()函数用法详解及增强函数
总结而言,`FIND_IN_SET()`是MySQL中处理由逗号分隔的字符串列表的一种便捷方法,尤其适用于列表相对较短且不经常更改的场景。然而,对于更为复杂的需要高性能和可扩展性的数据库设计,它可能不是最优选择,应考虑使用更加正规化的数据库结构。
999 2
mysql中find_in_set()函数用法详解及增强函数
【Elasticsearch】在es中实现mysql中的FIND_IN_SET查询条件
【Elasticsearch】在es中实现mysql中的FIND_IN_SET查询条件
181 0
MySQL外键约束行为解析:CASCADE, NO ACTION, RESTRICT, SET NULL
MySQL外键约束行为解析:CASCADE, NO ACTION, RESTRICT, SET NULL
888 0
【MySQL】init_connect='SET NAMES utf8',是干什么的?底层原理是什么?
【MySQL】init_connect='SET NAMES utf8',是干什么的?底层原理是什么?
909 0
mysql_config_editor 设置密码set --login_path
mysql_config_editor可以给指定的连接和密码生成一个加密文件.mylogin.cnf
206 0
MySQL 8 全局变量的修改持久化 set persist
在8之前的版本中,对于全局变量的修改,其只会影响其内存值,而不会持久化到配置文件中。数据库重启,又会恢复成修改前的值。从8开始,可通过SET PERSIST命令将全局变量的修改持久化到配置文件中。
401 0