说GTID - 与GTID相关的4个基本函数和使用场景
4个基本函数
1. GTID_SUBSET(set1,set2) - 若在set1中的GTID,也在set2中,返回true,否则返回false(set1是set2的子集)。
[root@mysql.sock][(none)]> SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23','3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57');
+-----------------------------------------------------------------------------------------------------+
| GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23','3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57') |
+-----------------------------------------------------------------------------------------------------+
| 1 |
+-----------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
[root@mysql.sock][(none)]> SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25','3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57');
+--------------------------------------------------------------------------------------------------------+
| GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25','3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57') |
+--------------------------------------------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
2. GTID_SUBTRACT(set1,set2) - 返回在set1中,不在set2中的GTID集合(set1和set2的差集)。
[root@mysql.sock][(none)]> SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57','3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25');
+----------------------------------------------------------------------------------------------------------+
| GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57','3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25') |
+----------------------------------------------------------------------------------------------------------+
| 3e11fa47-71ca-11e1-9e33-c80aa9429562:26-57 |
+----------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
[root@mysql.sock][(none)]> SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57','3E11FA47-71CA-11E1-9E33-C80AA9429562:23-24');
+----------------------------------------------------------------------------------------------------------+
| GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57','3E11FA47-71CA-11E1-9E33-C80AA9429562:23-24') |
+----------------------------------------------------------------------------------------------------------+
| 3e11fa47-71ca-11e1-9e33-c80aa9429562:21-22:25-57 |
+----------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
3. WAIT_FOR_EXECUTED_GTID_SET(gtid_set[, timeout]) - 等待gtid_set执行完,即GTID_SUBSET(gtid_subset, @@GLOBAL.gtid_executed)成立。timeout是可选的,超时参数。函数返回0,代表成功;返回1,代表超时;返回其它值,代表出错。
[root@mysql.sock][(none)]> SELECT WAIT_FOR_EXECUTED_GTID_SET('c4e5d4a0-a9be-11e9-b444-080027f22add:1-5',5);
+--------------------------------------------------------------------------+
| WAIT_FOR_EXECUTED_GTID_SET('c4e5d4a0-a9be-11e9-b444-080027f22add:1-5',5) |
+--------------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------------+
1 row in set (0.00 sec)
4. WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(gtid_set[, timeout][,channel]) - 和WAIT_FOR_EXECUTED_GTID_SET()类似,多了channel参数。
使用场景
1. 检查slave节点上是否执行了master上的所有GTIDs。
在salve节点上执行,SELECT GTID_SUBSET(master_gtid_executed, slave_gtid_executed),若返回0,说明slave节点上还有GTIDs未执行。
在slave节点上执行,SELECT GTID_SUBTRACT(master_gtid_executed, slave_gtid_executed),若返回GTIDs,也说明slave节点上还有GTIDs未执行。
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341