MySQL体验gtid复制过程
Posted 码城
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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个事务,且都已全部执行。
以上是关于MySQL体验gtid复制过程的主要内容,如果未能解决你的问题,请参考以下文章