MySQL体验gtid复制过程

体验gtid复制过程

更详细分析见

MySQL GTID快速了解 - 码到城攻GTID,全称 `Global transaction identifiers`,也称之为全局事务ID。是一种新的主从集群复制方式。GTID是用来代替传统复制的方法,GTID复制与普通复制模式的最大不同就是不需要指定二进制文件名和位置https://www.codecomeon.com/posts/190/
主:192.168.78.188 3308

    MySQL [(none)]> show variables like '%uuid%';
    +---------------+--------------------------------------+
    | Variable_name | Value                                |
    +---------------+--------------------------------------+
    | server_uuid   | 1d9b633d-e1ae-11ec-8ece-0242ac110002 |
    +---------------+--------------------------------------+
    1 row in set (0.01 sec)
    
    MySQL [(none)]> 


从:192.168.78.189 3306

    MySQL [(none)]> show variables like '%uuid%';
    +---------------+--------------------------------------+
    | Variable_name | Value                                |
    +---------------+--------------------------------------+
    | server_uuid   | f19b117a-cf6d-11ec-9fd7-0242ac110002 |
    +---------------+--------------------------------------+
    1 row in set (0.01 sec)
    
    MySQL [(none)]>


集群关系建立完成后,从节点执行如下命令,查看同步情况:

    MySQL [(none)]> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for source to send event
                      Master_Host: 192.168.78.188
                      Master_User: gtid_copy
                      Master_Port: 3308
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000001
              Read_Master_Log_Pos: 2507
                   Relay_Log_File: 67bf0b455536-relay-bin.000002
                    Relay_Log_Pos: 2723
            Relay_Master_Log_File: mysql-bin.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: 2507
                  Relay_Log_Space: 2940
                  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: 188
                      Master_UUID: 1d9b633d-e1ae-11ec-8ece-0242ac110002
                 Master_Info_File: mysql.slave_master_info
                        SQL_Delay: 0
              SQL_Remaining_Delay: NULL
          Slave_SQL_Running_State: Replica 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: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-10
                Executed_Gtid_Set: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-10
                    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.00 sec)
    
    ERROR: No query specified
    
    MySQL [(none)]>


之后在主库已经建好的表中,插入3条语句:

    MySQL [(none)]> use gtid_test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    MySQL [gtid_test]> insert into test values (1);
    Query OK, 1 row affected (0.00 sec)
    
    MySQL [gtid_test]> insert into test values (2);
    Query OK, 1 row affected (0.00 sec)
    
    MySQL [gtid_test]> insert into test values (3);
    Query OK, 1 row affected (0.00 sec)
    
    MySQL [gtid_test]>


在 `auto_commit=1`的前提下,插入3条语句,一共执行了3个事务。再次在从节点查询:

    MySQL [(none)]> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for source to send event
                      Master_Host: 192.168.78.188
                      Master_User: gtid_copy
                      Master_Port: 3308
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000001
              Read_Master_Log_Pos: 3362
                   Relay_Log_File: 67bf0b455536-relay-bin.000002
                    Relay_Log_Pos: 3578
            Relay_Master_Log_File: mysql-bin.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: 3362
                  Relay_Log_Space: 3795
                  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: 188
                      Master_UUID: 1d9b633d-e1ae-11ec-8ece-0242ac110002
                 Master_Info_File: mysql.slave_master_info
                        SQL_Delay: 0
              SQL_Remaining_Delay: NULL
          Slave_SQL_Running_State: Replica 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: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-13
                Executed_Gtid_Set: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-13
                    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.00 sec)
    
    ERROR: No query specified
    
    MySQL [(none)]>
主库执行 `show master status\G;`

    MySQL [gtid_test]> show master status\G;
    *************************** 1. row ***************************
                 File: mysql-bin.000001
             Position: 3362
         Binlog_Do_DB: 
     Binlog_Ignore_DB: 
    Executed_Gtid_Set: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-13
    1 row in set (0.00 sec)
    
    ERROR: No query specified
    
    MySQL [gtid_test]>


分析可得:

主库的 

    Executed_Gtid_Set 为:1d9b633d-e1ae-11ec-8ece-0242ac110002:1-13

从库的 

    Retrieved_Gtid_Set 为: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-13
    Executed_Gtid_Set为: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-13

也就是说主库产生了3个事务,从库接收到了主库的3个事务,且都已全部执行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值