Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Let's take a look at the killer new feature: gtid

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. A transaction will be given a gtid number. Take a look at the example:

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.01sec) 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 > quitBye [root@yw-gz-hd-test-211 ~] # cat / data/mysql3308/auto.cnf [auto] server-uuid=b526042e-89a7-11e8-bddb-000c29d7d637

Take a closer look at the above example, the current gtid:b526042e-89a7-11e8-bddb-000c29d7d637:1304086, and then I insert a piece of data, execute a transaction, gtid plus 1, becomes b526042e-89a7-11e8-bddb-000c29d7d637:1304087, then I use begin commit to mark another transaction, insert 2 pieces of data, gtid plus 1, becomes b526042e-89a7-11e8-bddb-000c29d7d637:1304088, and then I rollback,gtid without adding 1.

At this point, let's stop and think.

What is gtid? You got it, you got it.

two。 Why can gtid avoid repeated execution and data loss?

Take a look at the following example:

Mysql > SET @ @ SESSION.GTID_NEXT= 'b526042e-89a7-11e8murblybddbly000c29d7d637SESSION.GTID_NEXT= 1404076, 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,-> `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 color bddbwl000c29d7d637Switzerland 1304076mm.

The amount of information is a little large. A little understanding, first of all, I

SET @ @ SESSION.GTID_NEXT= 'b526042e-89a7-11e8 Israel bddbwy000c29d7d637Franco 1304076'

But the current gtid is b526042e-89a7-11e8-bddb-000c29d7d637:1-1304086. What do you mean, that is, 1304076 transactions are contained in 1-1304086. That is, the transaction has been executed and does not need to be executed any more. Do you understand?

Think about it.

If you understand this, you will see why I issued a create table command, and the query returned Query OK, 0 rows affected (0 sec).

It doesn't have any effect. It means that I have already executed this command create table, so I don't need to do it.

Let's look at the error: 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 color bddbwl000c29d7d637Switzerland 1304076mm.

This means that every time you execute a command, you must first execute set @ @ SESSION.GTID_NEXT = xxxxx.

What causes it?

Think about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report