MySQL的Retrieved_Gtid_Set、Executed_Gtid_Set哪里来

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 验证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)

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)

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)

master

root@localhost : hjj:13: > source /root/net_test.sql; 

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)

验证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)

总结

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文件的第一个事务开始应用
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
存储 关系型数据库 MySQL
MySql 字符串类型 - enum、set
MySql 字符串类型 - enum、set
41 0
|
关系型数据库 MySQL 数据库
MySQL中find_in_set函数的使用
1.语法 FIND_IN_SET(str,strlist) (1)str 要查询的字符串 (2)strlist 字段名; 参数以”,”分隔 如 (1,2,6,8) 查询字段(strlist)中包含(str)的结果,返回结果为null或记录 假如字符串str在由N个子链组成的字符串列表strlist 中,则返回值的范围在 1 到 N 之间。 一个字符串列表就是一个由一些被 ‘,’ 符号分开的子链组成的字符串。如果第一个参数是一个常数字符串,而第二个是type SET列,则FIND_IN_SET() 函数被优化,使用比特计算。 如果str不在strlist 或strlist 为空字符串,则返回
MySQL中find_in_set函数的使用
|
11月前
|
关系型数据库 MySQL 数据安全/隐私保护
mysql_config_editor 设置密码set --login_path
mysql_config_editor可以给指定的连接和密码生成一个加密文件.mylogin.cnf
103 0
|
11月前
|
关系型数据库 MySQL 数据库
MySQL 8 全局变量的修改持久化 set persist
在8之前的版本中,对于全局变量的修改,其只会影响其内存值,而不会持久化到配置文件中。数据库重启,又会恢复成修改前的值。从8开始,可通过SET PERSIST命令将全局变量的修改持久化到配置文件中。
171 0
|
SQL 存储 关系型数据库
【MySQL】init_connect='SET NAMES utf8',是干什么的?底层原理是什么?
【MySQL】init_connect='SET NAMES utf8',是干什么的?底层原理是什么?
557 0
|
存储 关系型数据库 MySQL
【MySQL】character-set-server=utf8,是干什么的?底层原理是什么?
【MySQL】character-set-server=utf8,是干什么的?底层原理是什么?
378 0
|
关系型数据库 MySQL
Mysql外键设置中的CASCADE、NO ACTION、RESTRICT、SET NULL
Mysql外键设置中的CASCADE、NO ACTION、RESTRICT、SET NULL
125 0
Mysql外键设置中的CASCADE、NO ACTION、RESTRICT、SET NULL
|
关系型数据库 MySQL 数据库
MySql常用函数(逻辑判断,字符串处理,日期函数)FIND_IN_SET、IF、ISNULL、IFNULL、NULLIF、SUBSTR、SUBSTRING_INDEX、CONCAT、LENGTH
MySql常用函数(逻辑判断,字符串处理,日期函数)FIND_IN_SET、IF、ISNULL、IFNULL、NULLIF、SUBSTR、SUBSTRING_INDEX、CONCAT、LENGTH
MySql常用函数(逻辑判断,字符串处理,日期函数)FIND_IN_SET、IF、ISNULL、IFNULL、NULLIF、SUBSTR、SUBSTRING_INDEX、CONCAT、LENGTH
|
SQL 关系型数据库 MySQL
MySQL 8.0.23上遇到一个FIND_IN_SET的BUG(一)
MySQL 8.0.23上遇到一个FIND_IN_SET的BUG(一)
121 0
MySQL 8.0.23上遇到一个FIND_IN_SET的BUG(一)