日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
深入理解MySQLGTID

GTID的概念

何為GITD

GTID(global transaction identifier)是全局事務(wù)標(biāo)識符,在mysql5.6版本中作為一個超級特性被推出。事務(wù)標(biāo)識不僅對于Master(起源)的服務(wù)器來說是惟一的,而且在整個復(fù)制拓?fù)浼軜?gòu)來說,也是全局唯一的。

1.GTID的格式

GTID = source_id:transaction_id

GTID分為兩部分,source_id和transaction_id。source_id是通過使用MySQL服務(wù)的server_uuid來表示 。transaction_id 是在事務(wù)提交的時候由系統(tǒng)順序分配的一個序列號。

使用show master status查看當(dāng)前實例執(zhí)行過的GTID事務(wù)信息。如下:

(root@localhost) [Ztest]> show master status\G;
*************************** 1. row ***************************
            File: mysql-bin.000005
        Position: 1959
    Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 4160e9b3-58d9-11e8-b174-005056af6f24:1-10
1 row in set (0.00 sec)

可以看出,本實例的source_id為4160e9b3-58d9-11e8-b174-005056af6f24,transaction_id為1-10,說明是提交了10個事務(wù)。

MySQL數(shù)據(jù)庫服務(wù)的uuid的查詢方式。

(root@localhost) [(none)]>  show GLOBAL VARIABLES like 'server_uuid';
+---------------+--------------------------------------+
| Variable_name | Value                                |
+---------------+--------------------------------------+
| server_uuid  | 4160e9b3-58d9-11e8-b174-005056af6f24 |
+---------------+--------------------------------------+
1 row in set (0.02 sec)

2.GTID的集合

GTID集合是一組全局事務(wù)標(biāo)識符,格式如下:

gtid_set:
    uuid_set [, uuid_set] ...
    | ''

uuid_set:
    uuid:interval[:interval]...

uuid:
    hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh

h:
    [0-9|A-F]

interval:
    n[-n]
    (n >= 1)

3.GTID的管理

MySQL庫中新增了gtid_exectued表,在MySQL 8.0中表結(jié)構(gòu)如下:

(root@localhost) [(none)]> use mysql
Database changed
(root@localhost) [mysql]> show create table gtid_executed \G;
*************************** 1. row ***************************
      Table: gtid_executed
Create Table: CREATE TABLE `gtid_executed` (
  `source_uuid` char(36) NOT NULL COMMENT 'uuid of the source where the transaction was originally executed.',
  `interval_start` bigint(20) NOT NULL COMMENT 'First number of interval.',
  `interval_end` bigint(20) NOT NULL COMMENT 'Last number of interval.',
  PRIMARY KEY (`source_uuid`,`interval_start`)
) /*!50100 TABLESPACE `mysql` */ ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

查看目前已經(jīng)執(zhí)行過的事務(wù),語句如下:

(root@localhost) [mysql]> select * from gtid_executed;
+--------------------------------------+----------------+--------------+
| source_uuid                          | interval_start | interval_end |
+--------------------------------------+----------------+--------------+
| 4160e9b3-58d9-11e8-b174-005056af6f24 |              1 |          26 |
+--------------------------------------+----------------+--------------+
1 row in set (0.01 sec)

可以分析
?當(dāng)未開啟binlog時,每個事務(wù)會記錄到gitd_executed表中。
?當(dāng)開啟binlog時,事務(wù)不會立即寫入gitd_executed表中,只有當(dāng)Binlog rotate輪詢時亦或者數(shù)據(jù)庫服務(wù)關(guān)閉時,會把事務(wù)寫入至gtid_executed表中。

實驗效果如下:

1.插入數(shù)據(jù)前的gtid_executed表的情況:

(root@localhost) [mysql]> select * from gtid_executed;
+--------------------------------------+----------------+--------------+
| source_uuid                          | interval_start | interval_end |
+--------------------------------------+----------------+--------------+
| 4160e9b3-58d9-11e8-b174-005056af6f24 |              1 |          26 |
+--------------------------------------+----------------+--------------+
1 row in set (0.01 sec)

2.插入準(zhǔn)備數(shù)據(jù):

insert into ztest.zstudent(stu_name,sex) values('hrd30','M');
insert into ztest.zstudent(stu_name,sex) values('hrd31','M');
commit;

3.插入數(shù)據(jù)后的gtid_executed表的情況:

(root@localhost) [mysql]> select * from gtid_executed;
+--------------------------------------+----------------+--------------+
| source_uuid                          | interval_start | interval_end |
+--------------------------------------+----------------+--------------+
| 4160e9b3-58d9-11e8-b174-005056af6f24 |              1 |          26 |
+--------------------------------------+----------------+--------------+
1 row in set (0.00 sec)

如上情況,沒有任何改變,Binlog rotate后,查看gtid_executed表的情況

(root@localhost) [mysql]> flush logs;
Query OK, 0 rows affected (0.01 sec)

(root@localhost) [mysql]> select * from gtid_executed;
+--------------------------------------+----------------+--------------+
| source_uuid                          | interval_start | interval_end |
+--------------------------------------+----------------+--------------+
| 4160e9b3-58d9-11e8-b174-005056af6f24 |              1 |          28 |
+--------------------------------------+----------------+--------------+
1 row in set (0.00 sec)

可以看到,上述提交的兩個事務(wù),在binlog刷新之后,寫入到了gitd_executed表中。

知識點備注:
RESET MASTER會清空gitd_executed表。


網(wǎng)站名稱:深入理解MySQLGTID
本文鏈接:http://www.dlmjj.cn/article/djcssge.html