再來理解一下殺手級新特性:gtid
1.一個事務,就會給一個gtid編號。來看看例子:
mysql> show master status; +---------------+----------+--------------+------------------+------------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +---------------+----------+--------------+------------------+------------------------------------------------+ | binlog.000017 | 58105 | | | b526042e-89a7-11e8-bddb-000c29d7d637:1-1304086 | +---------------+----------+--------------+------------------+------------------------------------------------+ 1 row in set (0.00 sec) mysql> insert into student(id) values(5); Query OK, 1 row affected (0.01 sec) mysql> show master status; +---------------+----------+--------------+------------------+------------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +---------------+----------+--------------+------------------+------------------------------------------------+ | binlog.000017 | 58432 | | | b526042e-89a7-11e8-bddb-000c29d7d637:1-1304087 | +---------------+----------+--------------+------------------+------------------------------------------------+ 1 row in set (0.00 sec) mysql> begin -> ; Query OK, 0 rows affected (0.00 sec) mysql> insert into student(id) values(6); Query OK, 1 row affected (0.00 sec) mysql> insert into student(id) values(7); Query OK, 1 row affected (0.00 sec) mysql> commit; Query OK, 0 rows affected (0.01 sec) mysql> show master status; +---------------+----------+--------------+------------------+------------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +---------------+----------+--------------+------------------+------------------------------------------------+ | binlog.000017 | 58918 | | | b526042e-89a7-11e8-bddb-000c29d7d637:1-1304088 | +---------------+----------+--------------+------------------+------------------------------------------------+ 1 row in set (0.00 sec) mysql> begin ; Query OK, 0 rows affected (0.00 sec) mysql> insert into student(id) values(8); Query OK, 1 row affected (0.00 sec) mysql> rollback; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +---------------+----------+--------------+------------------+------------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +---------------+----------+--------------+------------------+------------------------------------------------+ | binlog.000017 | 58918 | | | b526042e-89a7-11e8-bddb-000c29d7d637:1-1304088 | +---------------+----------+--------------+------------------+------------------------------------------------+ 1 row in set (0.00 sec) mysql> quit Bye [root@yw-gz-hd-test-211 ~]# cat /data/mysql3308/auto.cnf [auto] server-uuid=b526042e-89a7-11e8-bddb-000c29d7d637
仔細看看上面的例子,當前gtid:b526042e-89a7-11e8-bddb-000c29d7d637:1304086,然後我插入一條資料,執行一個事務,gtid加1,變成b526042e-89a7-11e8-bddb-000c29d7d637:1304087,然後我用begin commit,標誌另外一個事務,插入2條資料,gtid加1,變成b526042e-89a7-11e8-bddb-000c29d7d637:1304088,然後我rollback,gtid不加1.
到這裡,我們停下來,思考一下。。。。。。。。。。。
gtid是什麼東東?明白了吧,有所領悟了吧。
2.為什麼說gtid能避免重複執行,避免丟資料呢?
來看下下面這個例子:
mysql> SET @@SESSION.GTID_NEXT= 'b526042e-89a7-11e8-bddb-000c29d7d637:1304076'/*!*/; Query OK, 0 rows affected (0.00 sec) mysql> select * from student where id=4; +----+------+------+---------+---------+---------------------+---------------------+ | id | name | age | textcol | blobcol | birday | birday2 | +----+------+------+---------+---------+---------------------+---------------------+ | 4 | 3 | 3 | 3 | NULL | 2018-07-25 10:42:29 | 2018-07-25 10:42:33 | +----+------+------+---------+---------+---------------------+---------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `student` ( -> `id` int NOT NULL AUTO_INCREMENT , -> `name` varchar(255) NULL , -> `age` int NULL , -> `textcol` text NULL , -> `blobcol` blob NULL , -> `birday` timestamp NULL ON UPDATE CURRENT_TIMESTAMP , -> `birday2` datetime NULL ON UPDATE CURRENT_TIMESTAMP , -> PRIMARY KEY (`id`) -> ) -> ; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +---------------+----------+--------------+------------------+------------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +---------------+----------+--------------+------------------+------------------------------------------------+ | binlog.000017 | 58105 | | | b526042e-89a7-11e8-bddb-000c29d7d637:1-1304086 | +---------------+----------+--------------+------------------+------------------------------------------------+ 1 row in set (0.00 sec) mysql> insert into studnet(id) values(5); ERROR 1837 (HY000): When @@SESSION.GTID_NEXT is set to a GTID, you must explicitly set it to a different value after a COMMIT or ROLLBACK. Please check GTID_NEXT variable manual page for detailed explanation. Current @@SESSION.GTID_NEXT is 'b526042e-89a7-11e8-bddb-000c29d7d637:1304076'.
這個資訊量有點大。一點點理解,首先我
SET @@SESSION.GTID_NEXT= 'b526042e-89a7-11e8-bddb-000c29d7d637:1304076'
但是當前gtid是b526042e-89a7-11e8-bddb-000c29d7d637:1-1304086 。什麼意思,就是說1304076 事務包含在1-1304086。也就是說,這個事務已經執行了,不需要再執行了。理解了嗎?
思考一下。。。。。。。。。
這個理解通了,你就會發現,為什麼我釋出了一個create table 命令,查詢返回Query OK, 0 rows affected (0.00 sec)
就是什麼作用也沒有。意思就是說,這個命令create table 我已經執行過了,所以不需要執行。
再來看看錯誤:ERROR 1837 (HY000): When @@SESSION.GTID_NEXT is set to a GTID, you must explicitly set it to a different value after a COMMIT or ROLLBACK. Please check GTID_NEXT variable manual page for detailed explanation. Current @@SESSION.GTID_NEXT is 'b526042e-89a7-11e8-bddb-000c29d7d637:1304076'.
意思就是說,你每執行一個命令,都必須先執行 set @@SESSION.GTID_NEXT = xxxxx。
為什麼會這樣呢?
思考一下。。。。。。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30393770/viewspace-2158491/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 分享一下「廣告殺手」帶來的經驗
- MySQL5.6 GTID新特性實踐MySql
- Java三大特性再理解Java
- mysql5.6新特性GTID基本原理MySql
- Android Pie 引入 Keystore 新特性,安全防護再升級Android
- 深入理解 Redis 新特性:StreamRedis
- Solon 3.0 新特性:HttpUtils 瞭解一下HTTP
- 雲海再獲中國第一 OpenStack社群Xena版本新特性快來劃重點
- 再來溫習一下什麼是raid~AI
- 20 個殺手級 JavaScript 單行程式碼JavaScript行程
- mysqlbackup 重建帶有gtid特性的slaveMySql
- 新特性手冊12cr1
- 融合發展江蘇省未來網路創新研究院與新華三再牽手
- 開發者必讀:Oracle 12c新特性再總結Oracle
- Superedge的新特性和未來之路
- 10 殺手級的網路管理員的工具
- 7個殺手級的開源監測工具
- JDK6.0的新特性之三:理解StAXJDK
- 深入理解 Java17 新特性:Sealed ClassesJava
- webpack 4 新特性 & Vue-cli 升級WebVue
- AR眼鏡,機器學習領域的殺手級應用?機器學習
- Suse Linux10"殺手級"元件:AppArmor(轉)Linux元件APP
- Java 14 可能帶來什麼新特性?Java
- Java 9新特性解讀,等你來看Java
- Java8新特性都到碗裡來Java
- MySQL 5.7 新特性大全和未來展望MySql
- GCC 6 即將帶來的新特性GC
- 騰訊殺手級智慧手環Pacewear S8釋出 對飆小米手環?
- 深入理解ES8的新特性SharedArrayBuffer
- 再談特性切換
- 創新觸手可及: WebSphere CloudBurst V2.0 新特性WebCloud
- Oracle 12C 新特性之級聯truncateOracle
- fitbit運動手環有了新特性 升級App能幫你提升睡眠質量APP
- 蘋果手錶的新特性不妨猜猜看蘋果
- 舉個例子來理解一下Koa的洋蔥模型模型
- 7個殺手級的JS一行程式碼JS行程
- 程式設計師如何寫出殺手級的簡歷程式設計師
- Linux 缺乏一款殺手級應用程式嗎?Linux