{"id":667,"date":"2026-02-13T09:24:45","date_gmt":"2026-02-13T01:24:45","guid":{"rendered":"http:\/\/47.100.165.17\/wordpress\/?p=667"},"modified":"2026-02-13T09:24:46","modified_gmt":"2026-02-13T01:24:46","slug":"%e3%80%90mysql%e3%80%91gtid-%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%ef%bc%9a%e5%8e%9f%e7%90%86%e3%80%81%e9%83%a8%e7%bd%b2%e4%b8%8e%e9%81%bf%e5%9d%91%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/yunyanglib.cn\/?p=667","title":{"rendered":"\u3010MySQL\u3011GTID \u4e3b\u4ece\u590d\u5236\uff1a\u539f\u7406\u3001\u90e8\u7f72\u4e0e\u907f\u5751\u6307\u5357"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u5206\u5e03\u5f0f\u6570\u636e\u5e93\u67b6\u6784\u4e2d\uff0c\u4e3b\u4ece\u590d\u5236\u662f\u4fdd\u969c\u6570\u636e\u9ad8\u53ef\u7528\u3001\u8d1f\u8f7d\u5747\u8861\u7684\u6838\u5fc3\u65b9\u6848\u3002\u4f20\u7edf\u57fa\u4e8e Binlog \u4f4d\u70b9\u7684\u590d\u5236\u4f9d\u8d56\u624b\u52a8\u8bb0\u5f55\u504f\u79fb\u91cf\uff0c\u6545\u969c\u8f6c\u79fb\u65f6\u64cd\u4f5c\u7e41\u7410\u4e14\u6613\u51fa\u9519\u3002\u800c GTID\uff08\u5168\u5c40\u4e8b\u52a1\u6807\u8bc6\u7b26\uff09\u7684\u51fa\u73b0\uff0c\u8ba9\u4e3b\u4ece\u590d\u5236\u8fdb\u5165 \u201c\u4e8b\u52a1\u7ea7\u540c\u6b65\u201d \u65f6\u4ee3\uff0c\u5f7b\u5e95\u89e3\u51b3\u4e86\u4f4d\u70b9\u590d\u5236\u7684\u75db\u70b9\u3002\u672c\u6587\u5c06\u4ece\u539f\u7406\u3001\u4f18\u52bf\u3001\u5b9e\u64cd\u90e8\u7f72\u5230\u907f\u5751\u8981\u70b9\uff0c\u5168\u9762\u89e3\u6790 MySQL GTID \u4e3b\u4ece\u590d\u5236\u7684\u843d\u5730\u65b9\u6848\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"mlaMN\">\u4e00\u3001GTID \u6838\u5fc3\u539f\u7406\uff1a\u5168\u5c40\u4e8b\u52a1\u7684\u552f\u4e00\u6807\u8bc6<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u4ec0\u4e48\u662f GTID\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"uffb96ae8\">GTID\uff08Global Transaction Identifier\uff09\u662f MySQL \u4e3a\u6bcf\u4e2a\u4e8b\u52a1\u5206\u914d\u7684\u5168\u5c40\u552f\u4e00\u7f16\u53f7\uff0c\u683c\u5f0f\u4e3a<code>UUID:TID<\/code>\uff0c\u65e0\u8bba\u4e8b\u52a1\u5728\u54ea\u4e2a\u5b9e\u4f8b\u6267\u884c\uff0c\u90fd\u80fd\u901a\u8fc7\u8be5\u7f16\u53f7\u7cbe\u51c6\u8ffd\u8e2a\u3002\u5176\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e \u201c\u5168\u5c40\u552f\u4e00\u6027\u201d\uff0c\u8ba9\u4e8b\u52a1\u540c\u6b65\u8131\u79bb\u5bf9 Binlog \u6587\u4ef6\u540d\u548c\u504f\u79fb\u91cf\u7684\u4f9d\u8d56\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"TNKuR\">1.2 GTID \u7684\u7ec4\u6210\u7ed3\u6784<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u14efd470\">GTID \u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff0c\u683c\u5f0f\u4e3a <code>UUID:TID<\/code>\uff0c\u4e8c\u8005\u5171\u540c\u786e\u4fdd\u4e86\u4e8b\u52a1\u7684\u5168\u5c40\u552f\u4e00\u6027\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>UUID\uff08Universally Unique Identifier\uff09<\/strong>\uff1aMySQL \u5b9e\u4f8b\u7684\u552f\u4e00\u6807\u8bc6\u3002\u6bcf\u4e2a MySQL \u5b9e\u4f8b\u5728\u9996\u6b21\u542f\u52a8\u65f6\uff0c\u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u4e2a UUID \u5e76\u6301\u4e45\u5316\u5230 <code>data<\/code> \u76ee\u5f55\u4e0b\u7684 <code>auto.cnf<\/code> \u6587\u4ef6\u4e2d\uff0c\u5373\u4f7f\u5b9e\u4f8b\u91cd\u542f\u4e5f\u4e0d\u4f1a\u6539\u53d8\u3002<\/li>\n\n\n\n<li><strong>TID\uff08Transaction ID\uff09<\/strong>\uff1a\u4e8b\u52a1\u5728\u5f53\u524d\u5b9e\u4f8b\u4e0a\u7684 \u201c\u672c\u5730\u7f16\u53f7\u201d\uff0c\u4ee3\u8868\u8be5\u5b9e\u4f8b\u5df2\u7ecf\u63d0\u4ea4\u7684\u4e8b\u52a1\u6570\u91cf\uff0c\u4ece 1 \u5f00\u59cb\u9012\u589e\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"xbr6o\">1.3 \u5173\u952e\u67e5\u8be2\u547d\u4ee4<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u770b\u5f53\u524d\u5b9e\u4f8b\u7684 UUID\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"KzxVi\" class=\"wp-block-code\"><code>show global variables like \"server_uuid\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u3f7a174a\">\u4e0d\u540c MySQL \u5b9e\u4f8b\u7684 UUID \u5fc5\u7136\u4e0d\u540c\uff0c\u8fd9\u662f GTID \u5168\u5c40\u552f\u4e00\u6027\u7684\u57fa\u7840\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"825\" height=\"218\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-133.png\" alt=\"\" class=\"wp-image-670\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-133.png 825w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-133-300x79.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-133-768x203.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u770b <code>auto.cnf<\/code> \u6587\u4ef6\u4e2d\u7684 UUID\uff08\u6301\u4e45\u5316\u5b58\u50a8\uff09\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"afnFI\" class=\"wp-block-code\"><code>cat \/data\/mysql\/data\/auto.cnf<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"106\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-134-1024x106.png\" alt=\"\" class=\"wp-image-671\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-134-1024x106.png 1024w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-134-300x31.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-134-768x80.png 768w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-134.png 1030w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u770b\u5f53\u524d\u5b9e\u4f8b\u5df2\u7ecf\u63d0\u4ea4\u5e76\u4e14\u88ab purge\uff08\u6e05\u7406\uff09\u6389\u7684\u4e8b\u52a1\u5bf9\u5e94\u7684 GTIDs \u96c6\u5408\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"bL2VE\" class=\"wp-block-code\"><code>show global variables like \"gtid_purged\";<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"882\" height=\"214\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-136.png\" alt=\"\" class=\"wp-image-673\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-136.png 882w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-136-300x73.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-136-768x186.png 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u770b\u5f53\u524d\u5b9e\u4f8b\u5df2\u6267\u884c\u7684\u4e8b\u52a1 GTID \u96c6\u5408\uff08<code>gtid_executed<\/code>\uff09\uff1a<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u82b76d0d\">\u65b9\u5f0f\u4e00\uff1a\u901a\u8fc7\u7cfb\u7edf\u53d8\u91cf\u67e5\u770b<\/p>\n\n\n\n<pre id=\"AWrnj\" class=\"wp-block-code\"><code>show global variables like \"gtid_executed\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u63baf26c\">\u65b9\u5f0f\u4e8c\uff1a\u901a\u8fc7\u7cfb\u7edf\u8868\u67e5\u770b\uff08\u66f4\u8be6\u7ec6\uff09<\/p>\n\n\n\n<pre id=\"R2fjE\" class=\"wp-block-code\"><code>select * from mysql.gtid_executed;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"330\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-135-1024x330.png\" alt=\"\" class=\"wp-image-672\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-135-1024x330.png 1024w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-135-300x97.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-135-768x247.png 768w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-135.png 1090w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"u1AUV\">\u4e8c\u3001GTID \u6838\u5fc3\u914d\u7f6e\u53c2\u6570<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 gtid_mode\uff1aGTID \u5de5\u4f5c\u6a21\u5f0f\u5f00\u5173<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ud21ec628\"><code>gtid_mode<\/code> \u662f\u63a7\u5236 GTID \u5f00\u542f \/ \u5173\u95ed\u53ca\u5de5\u4f5c\u6a21\u5f0f\u7684\u5173\u952e\u53c2\u6570\uff0c\u5b83\u6709\u56db\u4e2a\u53d6\u503c\uff0c\u4e14<strong>\u53ea\u80fd\u76f8\u90bb\u5207\u6362<\/strong>\uff08\u4f8b\u5982\u4ece<code>off<\/code>\u5230<code>on<\/code>\u5fc5\u987b\u7ecf\u8fc7<code>off_permissive<\/code>\u2192<code>on_permissive<\/code>\uff09\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>\u53c2\u6570\u503c<\/td><td>\u542b\u4e49<\/td><\/tr><tr><td><code>off<\/code><\/td><td>\u65b0\u4e8b\u52a1\u548c\u590d\u5236\u4e8b\u52a1\u5747\u4e3a \u201c\u533f\u540d\u4e8b\u52a1\u201d\uff08\u65e0 GTID\uff09\uff0c\u5b8c\u5168\u7981\u7528 GTID<\/td><\/tr><tr><td><code>off_permissive<\/code><\/td><td>\u65b0\u4e8b\u52a1\u4e3a\u533f\u540d\u4e8b\u52a1\uff0c\u590d\u5236\u4e8b\u52a1\u53ef\u662f\u533f\u540d\u4e8b\u52a1\u6216 GTID \u4e8b\u52a1\uff08\u8fc7\u6e21\u6a21\u5f0f\uff09<\/td><\/tr><tr><td><code>on_permissive<\/code><\/td><td>\u65b0\u4e8b\u52a1\u4e3a GTID \u4e8b\u52a1\uff0c\u590d\u5236\u4e8b\u52a1\u53ef\u662f\u533f\u540d\u4e8b\u52a1\u6216 GTID \u4e8b\u52a1\uff08\u8fc7\u6e21\u6a21\u5f0f\uff09<\/td><\/tr><tr><td><code>on<\/code><\/td><td>\u65b0\u4e8b\u52a1\u548c\u590d\u5236\u4e8b\u52a1\u5747\u4e3a GTID \u4e8b\u52a1\uff0c\u5b8c\u5168\u542f\u7528 GTID<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ua5af2ce3\">\u67e5\u770b\u5f53\u524d <code>gtid_mode<\/code> \u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre id=\"OfqBy\" class=\"wp-block-code\"><code>show global variables like \"gtid_mode\";<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"JV0py\">2.2 enforce_gtid_consistency\uff1a\u4e00\u81f4\u6027\u6821\u9a8c\u5f00\u5173<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"uec3f6bf3\"><code>enforce_gtid_consistency<\/code> \u7528\u4e8e\u63a7\u5236\u4e8b\u52a1\u662f\u5426\u5141\u8bb8\u8fdd\u53cd GTID \u4e00\u81f4\u6027\u89c4\u5219\uff0c\u662f\u786e\u4fdd GTID \u590d\u5236\u6b63\u5e38\u8fd0\u884c\u7684 \u201c\u5b89\u5168\u9600\u201d\uff0c\u6709\u4e09\u4e2a\u53d6\u503c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>\u53c2\u6570\u503c<\/td><td>\u542b\u4e49<\/td><\/tr><tr><td><code>OFF<\/code><\/td><td>\u5141\u8bb8\u6240\u6709\u4e8b\u52a1\u8fdd\u53cd GTID \u4e00\u81f4\u6027\uff08\u4e0d\u63a8\u8350\uff0c\u53ef\u80fd\u5bfc\u81f4\u590d\u5236\u5f02\u5e38\uff09<\/td><\/tr><tr><td><code>ON<\/code><\/td><td>\u7981\u6b62\u4e8b\u52a1\u8fdd\u53cd GTID \u4e00\u81f4\u6027\uff0c\u4e00\u65e6\u8fdd\u53cd\u76f4\u63a5\u62a5\u9519\uff08\u751f\u4ea7\u73af\u5883\u63a8\u8350\uff09<\/td><\/tr><tr><td><code>WARN<\/code><\/td><td>\u5141\u8bb8\u8fdd\u53cd\u4e00\u81f4\u6027\uff0c\u4f46\u4f1a\u751f\u6210\u8b66\u544a\u65e5\u5fd7\uff08\u7528\u4e8e\u8fc1\u79fb\u524d\u7684\u517c\u5bb9\u6027\u6d4b\u8bd5\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Xtn6q\">\u5b9e\u6218\u9a8c\u8bc1\uff1a\u8fdd\u53cd GTID \u4e00\u81f4\u6027\u7684\u540e\u679c<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u0e1962c7\">\u5f53 <code>enforce_gtid_consistency = ON<\/code> \u65f6\uff0c\u82e5\u5728\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u540c\u65f6\u64cd\u4f5c InnoDB\uff08\u4e8b\u52a1\u5f15\u64ce\uff09\u548c MyISAM\uff08\u975e\u4e8b\u52a1\u5f15\u64ce\uff09\u8868\uff0c\u4f1a\u76f4\u63a5\u62a5\u9519\uff1a<\/p>\n\n\n\n<pre id=\"xwnKQ\" class=\"wp-block-code\"><code>-- \u5f00\u542f\u4e25\u683c\u4e00\u81f4\u6027\u6821\u9a8c\n\nset global enforce_gtid_consistency = on;\n\n-- \u521b\u5efa\u4e0d\u540c\u5f15\u64ce\u7684\u8868\n\ncreate table gtid_test1(a int)engine=innodb;\n\ncreate table gtid_test2(a int)engine=myisam;\n\n-- \u540c\u4e00\u4e8b\u52a1\u64cd\u4f5c\u4e24\u79cd\u5f15\u64ce\u8868\uff08\u8fdd\u53cd\u4e00\u81f4\u6027\uff09\n\nbegin;\n\ninsert into gtid_test1 select 1;\n\ninsert into gtid_test2 select 1;\n\ncommit; -- \u6267\u884c\u5931\u8d25\uff0c\u62a5\u9519\u63d0\u793a\u201c\u4e0d\u5141\u8bb8\u6df7\u5408\u4e8b\u52a1\/\u975e\u4e8b\u52a1\u5f15\u64ce\u201d<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/f6853ada50f3492cbf7fe3a154878090.png\" alt=\"\" title=\"null\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ucdf71bd4\">\u82e5\u5c06\u53c2\u6570\u6539\u4e3a <code>WARN<\/code>\uff0c\u4e0a\u8ff0\u64cd\u4f5c\u4f1a\u6267\u884c\u6210\u529f\uff0c\u4f46\u4f1a\u751f\u6210\u8b66\u544a\u65e5\u5fd7\uff0c\u53ef\u901a\u8fc7 <code>show warnings;<\/code> \u6216\u67e5\u770b MySQL \u9519\u8bef\u65e5\u5fd7\uff08<code>tail -n 10 \/data\/mysql\/log\/mysql.err<\/code>\uff09\u67e5\u770b\u8be6\u60c5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ufa06014e\"><img decoding=\"async\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/0c04ec74827d47959e639e8e9c7e7566.png\" width=\"1238\"><br>\u82e5\u5c06\u53c2\u6570\u6539\u4e3a <code>OFF<\/code>\uff0c\u4e0a\u8ff0\u64cd\u4f5c\u4f1a\u6b63\u5e38\u6267\u884c\u6210\u529f\uff0c\u4e5f\u4e0d\u4f1a\u751f\u6210\u8b66\u544a\u65e5\u5fd7\u3002<br><img decoding=\"async\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/edaf0856564e4bfb99705babfd2be163.png\" width=\"1137\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rcLl0\">\u4e09\u3001GTID \u590d\u5236\u7684\u6838\u5fc3\u4f18\u52bf<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"uef7a40e4\">\u4f20\u7edf\u57fa\u4e8e Binlog \u4f4d\u70b9\u7684\u590d\u5236\uff0c\u9700\u8981\u624b\u52a8\u8bb0\u5f55\u4e3b\u5e93\u7684 Binlog \u6587\u4ef6\u540d\u548c\u504f\u79fb\u91cf\uff08\u5982 <code>mysql-bin.000001:123<\/code>\uff09\uff0c\u4ece\u5e93\u901a\u8fc7\u8fd9\u4e9b \u201c\u4f4d\u70b9\u4fe1\u606f\u201d \u540c\u6b65\u6570\u636e\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728\u6545\u969c\u8f6c\u79fb\u3001\u4e3b\u4ece\u5207\u6362\u65f6\u975e\u5e38\u7e41\u7410\uff0c\u4e14\u5bb9\u6613\u56e0\u4f4d\u70b9\u8bb0\u5f55\u9519\u8bef\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u3002\u800c GTID \u590d\u5236\u6070\u597d\u89e3\u51b3\u4e86\u8fd9\u4e9b\u75db\u70b9\uff0c\u4e3b\u8981\u4f18\u52bf\u4f53\u73b0\u5728\u4e09\u65b9\u9762\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Fmuah\">3.1 \u7cbe\u51c6\u8ffd\u8e2a\u4e8b\u52a1\u6765\u6e90\uff1a\u77e5\u9053 \u201c\u4e8b\u52a1\u5728\u54ea\u4e2a\u5b9e\u4f8b\u4e0a\u63d0\u4ea4\u201d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u1ca02400\">GTID \u4e2d\u7684 UUID \u76f4\u63a5\u5173\u8054\u5230\u4e8b\u52a1\u7684 \u201c\u53d1\u6e90\u5730\u201d \u5b9e\u4f8b\uff0c\u65e0\u8bba\u4e8b\u52a1\u7ecf\u8fc7\u591a\u5c11\u6b21\u4e3b\u4ece\u5207\u6362\uff0c\u90fd\u80fd\u901a\u8fc7 GTID \u8ffd\u6eaf\u5230\u6700\u521d\u6267\u884c\u7684\u5b9e\u4f8b\u3002\u8fd9\u5bf9\u4e8e\u5206\u5e03\u5f0f\u67b6\u6784\uff08\u5982 MGR \u96c6\u7fa4\uff09\u7684\u4e8b\u52a1\u5ba1\u8ba1\u548c\u95ee\u9898\u6392\u67e5\u81f3\u5173\u91cd\u8981\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"iMuAM\">3.2 \u7b80\u5316\u6545\u969c\u8f6c\u79fb\uff1a\u65e0\u9700\u518d\u5173\u6ce8 Binlog \u4f4d\u70b9<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ud70aed57\">\u5728\u4f20\u7edf\u4f4d\u70b9\u590d\u5236\u4e2d\uff0c\u82e5\u4e3b\u5e93\u6545\u969c\uff0c\u63d0\u5347\u4e00\u4e2a\u4ece\u5e93\u4e3a\u65b0\u4e3b\u540e\uff0c\u5176\u4ed6\u4ece\u5e93\u9700\u8981\u624b\u52a8\u83b7\u53d6\u65b0\u4e3b\u7684 Binlog \u4f4d\u70b9\u624d\u80fd\u7ee7\u7eed\u540c\u6b65\uff0c\u64cd\u4f5c\u590d\u6742\u4e14\u6613\u51fa\u9519\u3002\u800c GTID \u590d\u5236\u4e2d\uff0c\u4ece\u5e93\u53ea\u9700\u901a\u8fc7 <code>MASTER_AUTO_POSITION = 1<\/code> \u914d\u7f6e\uff0c\u5c31\u80fd\u81ea\u52a8\u8bc6\u522b\u65b0\u4e3b\u7684 GTID \u96c6\u5408\uff0c\u65e0\u9700\u4eba\u5de5\u5e72\u9884\u4f4d\u70b9\uff0c\u6545\u969c\u8f6c\u79fb\u6548\u7387\u5927\u5e45\u63d0\u5347\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"GZvoe\">3.3 \u8f7b\u677e\u5224\u65ad\u4e3b\u4ece\u4e00\u81f4\u6027\uff1a\u57fa\u4e8e\u4e8b\u52a1\u7684 \u201c\u5929\u7136\u6821\u9a8c\u201d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u019b101d\">GTID \u590d\u5236\u7684\u6838\u5fc3\u662f \u201c\u4e8b\u52a1\u7ea7\u540c\u6b65\u201d\u2014\u2014 \u4ece\u5e93\u53ea\u4f1a\u540c\u6b65\u4e3b\u5e93\u5df2\u63d0\u4ea4\u7684 GTID \u4e8b\u52a1\uff0c\u4e14\u6bcf\u4e2a\u4e8b\u52a1\u53ea\u4f1a\u6267\u884c\u4e00\u6b21\uff08\u907f\u514d\u91cd\u590d\u6267\u884c\uff09\u3002\u901a\u8fc7\u5bf9\u6bd4\u4e3b\u4ece\u5e93\u7684 <code>gtid_executed<\/code> \u96c6\u5408\uff0c\u5c31\u80fd\u5feb\u901f\u5224\u65ad\u4e24\u8005\u7684\u6570\u636e\u662f\u5426\u4e00\u81f4\uff1a\u82e5\u96c6\u5408\u5b8c\u5168\u76f8\u540c\uff0c\u5219\u6570\u636e\u4e00\u81f4\uff1b\u82e5\u5b58\u5728\u5dee\u5f02\uff0c\u53ef\u76f4\u63a5\u901a\u8fc7\u7f3a\u5931\u7684 GTID \u8865\u5168\u6570\u636e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Wqpki\">\u56db\u3001GTID \u4f7f\u7528\u907f\u5751\u6307\u5357<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u467fb302\">GTID \u867d\u5f3a\u5927\uff0c\u4f46\u5e76\u975e \u201c\u4e07\u80fd\u201d\uff0c\u5728\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u9700\u4e25\u683c\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\uff0c\u5426\u5219\u53ef\u80fd\u5bfc\u81f4\u590d\u5236\u4e2d\u65ad\u6216\u6570\u636e\u4e0d\u4e00\u81f4\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"E34YZ\">4.1 \u7981\u6b62\u540c\u4e00\u4e8b\u52a1\u6df7\u5408\u4e8b\u52a1\u5f15\u64ce\u4e0e\u975e\u4e8b\u52a1\u5f15\u64ce<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u57956894\">\u5982\u524d\u6587\u6240\u8ff0\uff0cInnoDB\uff08\u4e8b\u52a1\u5f15\u64ce\uff09\u548c MyISAM\uff08\u975e\u4e8b\u52a1\u5f15\u64ce\uff09\u7684\u4e8b\u52a1\u7279\u6027\u4e0d\u540c\uff0c\u6df7\u5408\u64cd\u4f5c\u4f1a\u5bfc\u81f4\u4e00\u4e2a\u4e8b\u52a1\u88ab\u5206\u914d\u591a\u4e2a GTID\uff0c\u7834\u574f GTID \u7684\u552f\u4e00\u6027\uff0c\u6700\u7ec8\u5f15\u53d1\u590d\u5236\u5f02\u5e38\u3002\u751f\u4ea7\u73af\u5883\u4e2d\u5e94\u5f7b\u5e95\u6dd8\u6c70 MyISAM \u5f15\u64ce\uff0c\u7edf\u4e00\u4f7f\u7528 InnoDB\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"TPr0y\">4.2 \u8c28\u614e\u4f7f\u7528 <code>CREATE TABLE ... SELECT<\/code> \u8bed\u53e5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u1270dad5\">\u5728 MySQL 8.0.21 \u4e4b\u524d\uff0c\u82e5 Binlog \u683c\u5f0f\u4e3a <code>ROW<\/code>\uff08\u751f\u4ea7\u73af\u5883\u63a8\u8350\u683c\u5f0f\uff09\uff0c<code>CREATE TABLE ... SELECT<\/code> \u4f1a\u88ab\u62c6\u5206\u4e3a\u4e24\u4e2a\u72ec\u7acb\u4e8b\u4ef6\uff1a\u201c\u521b\u5efa\u8868\u201d \u548c \u201c\u63d2\u5165\u6570\u636e\u201d\uff0c\u8fd9\u4e24\u4e2a\u4e8b\u4ef6\u4f1a\u88ab\u5206\u914d\u4e0d\u540c\u7684 GTID\uff0c\u5bfc\u81f4\u590d\u5236\u4e0d\u4e00\u81f4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"uac972a1b\"><strong>\u89e3\u51b3\u65b9\u6848<\/strong>\uff1a\u5347\u7ea7 MySQL \u5230 8.0.21 \u53ca\u4ee5\u4e0a\u7248\u672c\uff08\u8be5\u7248\u672c\u5c06\u5176\u4f18\u5316\u4e3a\u539f\u5b50 DDL\uff0c\u4ec5\u5206\u914d\u4e00\u4e2a GTID\uff09\uff0c\u6216\u907f\u514d\u4f7f\u7528\u8be5\u8bed\u53e5\uff0c\u62c6\u5206\u4e3a \u201c\u521b\u5efa\u8868\u201d \u548c \u201cINSERT SELECT\u201d \u4e24\u6b65\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"peKy4\">4.3 \u751f\u4ea7\u73af\u5883\u5fc5\u987b\u5f00\u542f <code>enforce_gtid_consistency = ON<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u9298eab6\"><code>enforce_gtid_consistency<\/code> \u662f GTID \u590d\u5236\u7684 \u201c\u5b89\u5168\u5c4f\u969c\u201d\uff0c\u5f00\u542f\u540e\u80fd\u81ea\u52a8\u62e6\u622a\u8fdd\u53cd\u4e00\u81f4\u6027\u7684\u4e8b\u52a1\uff0c\u907f\u514d\u56e0\u4e0d\u89c4\u8303 SQL \u5bfc\u81f4\u590d\u5236\u4e2d\u65ad\u3002\u5207\u52ff\u4e3a\u4e86 \u201c\u56fe\u65b9\u4fbf\u201d \u5c06\u5176\u8bbe\u7f6e\u4e3a <code>OFF<\/code> \u6216 <code>WARN<\/code>\uff08\u4ec5\u8fc1\u79fb\u6d4b\u8bd5\u9636\u6bb5\u53ef\u4e34\u65f6\u4f7f\u7528 <code>WARN<\/code>\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5b9e\u6218\u90e8\u7f72\uff1a\u4e24\u79cd\u573a\u666f\u7684 GTID \u590d\u5236\u642d\u5efa<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"aQdtH\">\u573a\u666f 1\uff1a\u4ece\u4f20\u7edf\u4f4d\u70b9\u590d\u5236\u8fc1\u79fb\u5230 GTID \u590d\u5236<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u72e2e212\">\u82e5\u5df2\u6709\u57fa\u4e8e\u4f4d\u70b9\u7684\u4e3b\u4ece\u590d\u5236\u67b6\u6784\uff0c\u65e0\u9700\u91cd\u5efa\u96c6\u7fa4\u5373\u53ef\u5e73\u6ed1\u8fc1\u79fb\u5230 GTID \u590d\u5236\uff0c\u6b65\u9aa4\u5982\u4e0b\uff08\u4e3b\u5e93\u548c\u4ece\u5e93\u5747\u9700\u6267\u884c\uff09\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ItXzC\">\u6b65\u9aa4 1\uff1a\u67e5\u770b\u5f53\u524d GTID \u72b6\u6001<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u1537a1d0\">\u5148\u786e\u8ba4 <code>gtid_mode<\/code> \u548c <code>enforce_gtid_consistency<\/code> \u7684\u5f53\u524d\u503c\uff0c\u786e\u4fdd\u8fc1\u79fb\u524d\u7684\u521d\u59cb\u72b6\u6001\u6e05\u6670\uff1a<\/p>\n\n\n\n<pre id=\"j8oo3\" class=\"wp-block-code\"><code>show global variables like 'gtid_mode';\n\nshow global variables like 'enforce_gtid_consistency';<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"384\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-137.png\" alt=\"\" class=\"wp-image-677\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-137.png 881w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-137-300x131.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-137-768x335.png 768w\" sizes=\"(max-width: 881px) 100vw, 881px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"TSzqf\">\u6b65\u9aa4 2\uff1a\u5f00\u542f WARN \u6a21\u5f0f\uff0c\u517c\u5bb9\u6027\u6d4b\u8bd5<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u523ea3c2\">\u5c06 <code>enforce_gtid_consistency<\/code> \u8bbe\u4e3a <code>WARN<\/code>\uff0c\u8ba9\u6570\u636e\u5e93\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\uff08\u5efa\u8bae 1-2 \u5929\uff09\uff0c\u89c2\u5bdf\u9519\u8bef\u65e5\u5fd7\u662f\u5426\u6709\u8fdd\u53cd GTID \u4e00\u81f4\u6027\u7684\u8b66\u544a\uff1a<\/p>\n\n\n\n<pre id=\"AHLGp\" class=\"wp-block-code\"><code>SET GLOBAL ENFORCE_GTID_CONSISTENCY = WARN;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ub631e410\">\u82e5\u6709\u8b66\u544a\uff0c\u9700\u5148\u4f18\u5316\u5bf9\u5e94\u7684 SQL \u8bed\u53e5\uff08\u5982\u62c6\u5206\u6df7\u5408\u5f15\u64ce\u4e8b\u52a1\u3001\u66ff\u6362 <code>CREATE TABLE ... SELECT<\/code>\uff09\uff0c\u786e\u4fdd\u65e0\u517c\u5bb9\u6027\u95ee\u9898\u540e\u518d\u7ee7\u7eed\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"252\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-138.png\" alt=\"\" class=\"wp-image-678\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-138.png 1002w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-138-300x75.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-138-768x193.png 768w\" sizes=\"(max-width: 1002px) 100vw, 1002px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"nTlYx\">\u6b65\u9aa4 3\uff1a\u5f00\u542f\u4e25\u683c\u4e00\u81f4\u6027\u6821\u9a8c\uff08ON\uff09<\/h4>\n\n\n\n<pre id=\"EqphN\" class=\"wp-block-code\"><code>SET GLOBAL ENFORCE_GTID_CONSISTENCY = ON;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u69d3b177\">\u6b64\u65f6\u82e5\u6709\u8fdd\u53cd\u4e00\u81f4\u6027\u7684\u4e8b\u52a1\uff0c\u4f1a\u76f4\u63a5\u62a5\u9519\uff0c\u9700\u7acb\u5373\u5904\u7406\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"279\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-139.png\" alt=\"\" class=\"wp-image-679\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-139.png 1001w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-139-300x84.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-139-768x214.png 768w\" sizes=\"(max-width: 1001px) 100vw, 1001px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"y3LSH\">\u6b65\u9aa4 4\uff1a\u5207\u6362 gtid_mode \u5230\u8fc7\u6e21\u6a21\u5f0f<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u7229db51\">\u6309 \u201c\u76f8\u90bb\u5207\u6362\u201d \u539f\u5219\uff0c\u9010\u6b65\u5c06 <code>gtid_mode<\/code> \u4ece <code>off<\/code> \u5207\u6362\u5230 <code>on<\/code>\uff1a<\/p>\n\n\n\n<pre id=\"AP5lC\" class=\"wp-block-code\"><code>-- \u7b2c\u4e00\u6b65\uff1a\u5207\u6362\u5230off_permissive\n\nSET GLOBAL GTID_MODE = OFF_PERMISSIVE;\n\n-- \u7b2c\u4e8c\u6b65\uff1a\u5207\u6362\u5230on_permissive\n\nSET GLOBAL GTID_MODE = ON_PERMISSIVE;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"448\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-140.png\" alt=\"\" class=\"wp-image-680\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-140.png 1001w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-140-300x134.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-140-768x344.png 768w\" sizes=\"(max-width: 1001px) 100vw, 1001px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"UyRtk\">\u6b65\u9aa4 5\uff1a\u7b49\u5f85\u533f\u540d\u4e8b\u52a1\u6e05\u7a7a<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ueac43edb\">\u67e5\u770b <code>ONGOING_ANONYMOUS_TRANSACTION_COUNT<\/code>\uff0c\u786e\u4fdd\u6240\u6709\u533f\u540d\u4e8b\u52a1\uff08\u8fc1\u79fb\u524d\u7684\u4e8b\u52a1\uff09\u6267\u884c\u5b8c\u6bd5\uff1a<\/p>\n\n\n\n<pre id=\"CWgBt\" class=\"wp-block-code\"><code>SHOW STATUS LIKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1012\" height=\"206\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-142.png\" alt=\"\" class=\"wp-image-682\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-142.png 1012w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-142-300x61.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-142-768x156.png 768w\" sizes=\"(max-width: 1012px) 100vw, 1012px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u5295e9d4\">\u5f53\u503c\u4e3a <code>0<\/code> \u65f6\uff0c\u8bf4\u660e\u6240\u6709\u65e7\u4e8b\u52a1\u5df2\u5904\u7406\u5b8c\u6210\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"pu1a0\">\u6b65\u9aa4 6\uff1a\u6b63\u5f0f\u5f00\u542f GTID<\/h4>\n\n\n\n<pre id=\"hlYIp\" class=\"wp-block-code\"><code>SET GLOBAL GTID_MODE = ON;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"995\" height=\"269\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-141.png\" alt=\"\" class=\"wp-image-681\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-141.png 995w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-141-300x81.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-141-768x208.png 768w\" sizes=\"(max-width: 995px) 100vw, 995px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ymUDg\">\u6b65\u9aa4 7\uff1a\u53c2\u6570\u6301\u4e45\u5316\uff08\u907f\u514d\u91cd\u542f\u5931\u6548\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ue5816f05\">\u7f16\u8f91 MySQL \u914d\u7f6e\u6587\u4ef6 <code>my.cnf<\/code>\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre id=\"J4gz8\" class=\"wp-block-code\"><code>gtid_mode=ON\n\nenforce_gtid_consistency=ON<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"kIn5l\">\u6b65\u9aa4 8\uff1a\u4fee\u6539\u4ece\u5e93\u590d\u5236\u53c2\u6570\uff0c\u542f\u7528 GTID \u540c\u6b65<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u4be0e192\">\u5728\u6240\u6709\u4ece\u5e93\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5207\u6362\u5230 GTID \u590d\u5236\u6a21\u5f0f\uff1a<\/p>\n\n\n\n<pre id=\"lj0K0\" class=\"wp-block-code\"><code>-- \u505c\u6b62\u4ece\u5e93\u590d\u5236\n\nstop slave;\n\n-- \u542f\u7528\u81ea\u52a8GTID\u5b9a\u4f4d\uff08\u65e0\u9700\u6307\u5b9aBinlog\u4f4d\u70b9\uff09\n\nCHANGE MASTER TO MASTER_AUTO_POSITION = 1;\n\n-- \u91cd\u542f\u4ece\u5e93\u590d\u5236\n\nSTART SLAVE;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"194\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-143.png\" alt=\"\" class=\"wp-image-683\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-143.png 1001w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-143-300x58.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-143-768x149.png 768w\" sizes=\"(max-width: 1001px) 100vw, 1001px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"dLj7D\">\u6b65\u9aa4 9\uff1a\u9a8c\u8bc1\u8fc1\u79fb\u7ed3\u679c<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u96fc0541\">\u5728\u4e3b\u5e93\u6267\u884c\u6d4b\u8bd5\u4e8b\u52a1\uff08\u5982\u521b\u5efa\u8868\u3001\u63d2\u5165\u6570\u636e\uff09\uff0c\u7136\u540e\u5728\u4ece\u5e93\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b GTID \u540c\u6b65\u60c5\u51b5\uff1a<\/p>\n\n\n\n<pre id=\"wO2Q6\" class=\"wp-block-code\"><code>-- \u4e3b\u5e93\u6267\u884c\u6d4b\u8bd5\u4e8b\u52a1\n\ncreate table t1_gtid(id int);\n\ninsert into t1_gtid select 1;\n\n-- \u4ece\u5e93\u9a8c\u8bc1\n\nshow slave status\\G -- \u67e5\u770bRetrieved_Gtid_Set\u548cExecuted_Gtid_Set\n\nselect * from t1_gtid;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u896436cd\">\u82e5 <code>Retrieved_Gtid_Set<\/code>\uff08\u5df2\u63a5\u6536\u7684 GTID\uff09\u548c <code>Executed_Gtid_Set<\/code>\uff08\u5df2\u6267\u884c\u7684 GTID\uff09\u5305\u542b\u4e3b\u5e93\u65b0\u751f\u6210\u7684 GTID\uff0c\u5219\u8fc1\u79fb\u6210\u529f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"998\" height=\"193\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-144.png\" alt=\"\" class=\"wp-image-684\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-144.png 998w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-144-300x58.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-144-768x149.png 768w\" sizes=\"(max-width: 998px) 100vw, 998px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"530\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-145-1024x530.png\" alt=\"\" class=\"wp-image-685\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-145-1024x530.png 1024w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-145-300x155.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-145-768x397.png 768w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-145.png 1535w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"UHHym\">\u573a\u666f 2\uff1a\u4ece\u96f6\u642d\u5efa GTID \u590d\u5236\u67b6\u6784<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"uc77f2edb\">\u82e5\u9700\u65b0\u5efa MySQL \u4e3b\u4ece\u590d\u5236\uff0c\u76f4\u63a5\u91c7\u7528 GTID \u6a21\u5f0f\u53ef\u5927\u5e45\u7b80\u5316\u90e8\u7f72\u6d41\u7a0b\uff0c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"eG6tN\">\u6b65\u9aa4 1\uff1a\u786e\u4fdd\u4e3b\u5e93\u5f00\u542f Binlog<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ua2f6ee5c\">GTID \u590d\u5236\u4f9d\u8d56 Binlog \u8bb0\u5f55\u4e8b\u52a1\uff0c\u9700\u5148\u786e\u8ba4\u4e3b\u5e93\u5df2\u5f00\u542f Binlog\uff1a<\/p>\n\n\n\n<pre id=\"wKwHE\" class=\"wp-block-code\"><code>show global variables like \"log_bin\";<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"998\" height=\"213\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-146.png\" alt=\"\" class=\"wp-image-686\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-146.png 998w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-146-300x64.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-146-768x164.png 768w\" sizes=\"(max-width: 998px) 100vw, 998px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u3fd2e038\">\u82e5\u672a\u5f00\u542f\uff0c\u9700\u5728 <code>my.cnf<\/code> \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\u5e76\u91cd\u542f\u4e3b\u5e93\uff1a<\/p>\n\n\n\n<pre id=\"qjy8a\" class=\"wp-block-code\"><code>log_bin=\/data\/mysql\/binlog\/mysql-bin\n\nserver_id=184151  # \u4e3b\u5e93\u552f\u4e00ID\uff08\u4ece\u5e93\u9700\u4e0d\u540c\uff09<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"IzmOU\">\u6b65\u9aa4 2\uff1a\u914d\u7f6e\u4e3b\u4ece\u5e93\u7684 server_id\uff08\u552f\u4e00\u4e14\u4e0d\u540c\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ue052d4a2\">\u4e3b\u5e93\u548c\u4ece\u5e93\u7684 <code>server_id<\/code> \u5fc5\u987b\u552f\u4e00\uff0c\u907f\u514d\u51b2\u7a81\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u770b\u5f53\u524d <code>server_id<\/code>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"bxEZL\" class=\"wp-block-code\"><code>select @@global.server_id;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u52a8\u6001\u4fee\u6539\uff08\u4e34\u65f6\u751f\u6548\uff09\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"TYkAO\" class=\"wp-block-code\"><code>set global server_id=184152;  # \u4ece\u5e93ID\uff0c\u9700\u4e0e\u4e3b\u5e93\u4e0d\u540c<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6301\u4e45\u5316\u5230 <code>my.cnf<\/code>\uff08\u6c38\u4e45\u751f\u6548\uff09\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"RYQeq\" class=\"wp-block-code\"><code>server_id=184152<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"eafCD\">\u6b65\u9aa4 3\uff1a\u4e3b\u4ece\u5e93\u5747\u5f00\u542f GTID\uff08\u540c\u8fc1\u79fb\u6b65\u9aa4 3-7\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"uf832c5dd\">\u4e3b\u5e93\u548c\u4ece\u5e93\u5747\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff0c\u5f00\u542f GTID\uff1a<\/p>\n\n\n\n<pre id=\"qlrRO\" class=\"wp-block-code\"><code>SET GLOBAL ENFORCE_GTID_CONSISTENCY = WARN;\n\n-- \u89c2\u5bdf\u65e0\u8b66\u544a\u540e\u6267\u884c\n\nSET GLOBAL ENFORCE_GTID_CONSISTENCY = ON;\n\nSET GLOBAL GTID_MODE = OFF_PERMISSIVE;\n\nSET GLOBAL GTID_MODE = ON_PERMISSIVE;\n\n-- \u7b49\u5f85ONGOING_ANONYMOUS_TRANSACTION_COUNT=0\nshow status like 'ongoing_anonyous_transaction_count';\n\nSET GLOBAL GTID_MODE = ON;\n\n-- \u6301\u4e45\u5316\u914d\u7f6e\u5230my.cnf\nvim \/data\/mysql\/cond\/my.cf\ngtid_mode=ON\nenforce_gtid_consistency=ON<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"tYMyM\">\u6b65\u9aa4 4\uff1a\u4e3b\u5e93\u521b\u5efa\u590d\u5236\u7528\u6237<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ud47e26cf\">\u521b\u5efa\u7528\u4e8e\u4ece\u5e93\u540c\u6b65\u7684\u7528\u6237\uff0c\u5e76\u6388\u4e88 <code>REPLICATION SLAVE<\/code> \u6743\u9650\uff1a<\/p>\n\n\n\n<pre id=\"yhUNM\" class=\"wp-block-code\"><code>CREATE USER 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'Uid_dQc63';\n\nGRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"BLObQ\">\u6b65\u9aa4 5\uff1a\u4e3b\u5e93\u5bfc\u51fa\u6570\u636e\uff08\u542b GTID \u4fe1\u606f\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u05108d34\">\u4f7f\u7528 <code>mysqldump<\/code> \u5bfc\u51fa\u4e3b\u5e93\u5168\u91cf\u6570\u636e\uff0c\u5e76\u901a\u8fc7 <code>--set-gtid-purged=on<\/code> \u4fdd\u7559 GTID \u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre id=\"LlOrM\" class=\"wp-block-code\"><code>cd \/data\/backup\/\n\nmysqldump -uroot -p --single-transaction --all-databases --master-data=2 --set-gtid-purged=on &gt; alldb_bak_for_gtid.sql<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>--single-transaction<\/code>\uff1a\u786e\u4fdd\u5bfc\u51fa\u6570\u636e\u65f6\u4e0d\u9501\u8868\uff08InnoDB \u5f15\u64ce\uff09\u3002<\/li>\n\n\n\n<li><code>--master-data=2<\/code>\uff1a\u8bb0\u5f55\u4e3b\u5e93 Binlog \u4fe1\u606f\uff08\u4fbf\u4e8e\u8c03\u8bd5\uff09\u3002<\/li>\n\n\n\n<li><code>--set-gtid-purged=on<\/code>\uff1a\u5bfc\u51fa\u6587\u4ef6\u4e2d\u5305\u542b GTID \u76f8\u5173\u914d\u7f6e\uff0c\u786e\u4fdd\u4ece\u5e93\u5bfc\u5165\u540e\u540c\u6b65\u8d77\u70b9\u6b63\u786e\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"107\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-148-1024x107.png\" alt=\"\" class=\"wp-image-688\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-148-1024x107.png 1024w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-148-300x31.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-148-768x80.png 768w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-148-1536x161.png 1536w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-148.png 1893w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Gd8QU\">\u6b65\u9aa4 6\uff1a\u4ece\u5e93\u5bfc\u5165\u6570\u636e<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ube398bc0\">\u5c06\u4e3b\u5e93\u7684\u5907\u4efd\u6587\u4ef6\u4f20\u8f93\u5230\u4ece\u5e93\uff0c\u5e76\u6267\u884c\u5bfc\u5165\uff1a<\/p>\n\n\n\n<pre id=\"uPS7n\" class=\"wp-block-code\"><code># \u4f20\u8f93\u5907\u4efd\u6587\u4ef6\uff08\u4e3b\u5e93\u6267\u884c\uff09\n\nscp alldb_bak_for_gtid.sql 192.168.184.152:\/data\/backup\n\n# \u4ece\u5e93\u5bfc\u5165\u524d\u6e05\u7a7agtid_executed\n\nreset master;\n\n# \u5bfc\u5165\u6570\u636e\n\nmysql -uroot -p &lt; \/data\/backup\/alldb_bak_for_gtid.sql<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"VGtQu\">\u6b65\u9aa4 7\uff1a\u4ece\u5e93\u914d\u7f6e\u4e3b\u5e93\u4fe1\u606f\uff0c\u5f00\u542f GTID \u590d\u5236<\/h4>\n\n\n\n<pre id=\"llXTQ\" class=\"wp-block-code\"><code>stop slave;\n\nreset slave;\n\n-- \u914d\u7f6e\u4e3b\u5e93\u5730\u5740\u3001\u590d\u5236\u7528\u6237\u3001\u542f\u7528GTID\u81ea\u52a8\u5b9a\u4f4d\n\nchange master to \n\nmaster_host='192.168.184.151',  # \u4e3b\u5e93IP\n\nmaster_user='repl',             # \u590d\u5236\u7528\u6237\n\nmaster_password='Uid_dQc63',    # \u590d\u5236\u7528\u6237\u5bc6\u7801\n\nMASTER_AUTO_POSITION=1;         # \u542f\u7528GTID\u81ea\u52a8\u540c\u6b65\n\n-- \u542f\u52a8\u4ece\u5e93\u590d\u5236\n\nstart slave;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"AwBCN\">\u6b65\u9aa4 8\uff1a\u9a8c\u8bc1 GTID \u590d\u5236\u6548\u679c<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e3b\u5e93\u6267\u884c\u6d4b\u8bd5\u4e8b\u52a1\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"yB4ha\" class=\"wp-block-code\"><code>create table t1_gtid(id int);\n\ninsert into t1_gtid values (1,2);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4ece\u5e93\u9a8c\u8bc1\u6570\u636e\u540c\u6b65\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"f5Lpl\" class=\"wp-block-code\"><code>-- \u67e5\u770b\u6570\u636e\u662f\u5426\u5b58\u5728\n\nselect * from t1_gtid;\n\n-- \u67e5\u770bGTID\u540c\u6b65\u72b6\u6001\n\nshow slave status\\G<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u1b6846f2\">\u82e5\u4ece\u5e93\u80fd\u67e5\u8be2\u5230 <code>t1_gtid<\/code> \u8868\u53ca\u6570\u636e\uff0c\u4e14 <code>Retrieved_Gtid_Set<\/code> \u548c <code>Executed_Gtid_Set<\/code> \u5305\u542b\u4e3b\u5e93\u7684 GTID\uff0c\u5219\u4ece\u96f6\u642d\u5efa\u7684 GTID \u590d\u5236\u67b6\u6784\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"581\" src=\"http:\/\/47.100.165.17\/wordpress\/wp-content\/uploads\/2026\/02\/image-149-1024x581.png\" alt=\"\" class=\"wp-image-689\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-149-1024x581.png 1024w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-149-300x170.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-149-768x436.png 768w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/02\/image-149.png 1401w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u603b\u7ed3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">GTID \u590d\u5236\u901a\u8fc7 \u201c\u5168\u5c40\u4e8b\u52a1\u6807\u8bc6\u201d \u5f7b\u5e95\u89e3\u51b3\u4e86\u4f20\u7edf\u4f4d\u70b9\u590d\u5236\u7684\u75db\u70b9\uff0c\u7b80\u5316\u4e86\u4e3b\u4ece\u67b6\u6784\u7684\u90e8\u7f72\u4e0e\u7ef4\u62a4\uff0c\u662f MySQL \u9ad8\u53ef\u7528\u65b9\u6848\u7684\u9996\u9009\u3002\u6838\u5fc3\u5728\u4e8e\u628a\u63e1\u4e09\u4e2a\u5173\u952e\u70b9\uff1a\u6b63\u786e\u914d\u7f6e<code>gtid_mode<\/code>\u548c<code>enforce_gtid_consistency<\/code>\u53c2\u6570\u3001\u9075\u5faa GTID \u4e00\u81f4\u6027\u89c4\u5219\u3001\u6309\u89c4\u8303\u5b8c\u6210\u6a21\u5f0f\u5207\u6362\u4e0e\u90e8\u7f72\u3002\u65e0\u8bba\u662f\u5b58\u91cf\u96c6\u7fa4\u8fc1\u79fb\u8fd8\u662f\u65b0\u5efa\u67b6\u6784\uff0c\u6309\u672c\u6587\u6b65\u9aa4\u64cd\u4f5c\u5747\u53ef\u5feb\u901f\u843d\u5730\uff0c\u540c\u65f6\u89c4\u907f\u5e38\u89c1\u5751\u70b9\uff0c\u4fdd\u969c\u6570\u636e\u540c\u6b65\u7684\u7a33\u5b9a\u6027\u4e0e\u4e00\u81f4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5206\u5e03\u5f0f\u6570\u636e\u5e93\u67b6\u6784\u4e2d\uff0c\u4e3b\u4ece\u590d\u5236\u662f\u4fdd\u969c\u6570\u636e\u9ad8\u53ef\u7528\u3001\u8d1f\u8f7d\u5747\u8861\u7684\u6838\u5fc3\u65b9\u6848\u3002\u4f20\u7edf\u57fa\u4e8e Binlog \u4f4d\u70b9\u7684\u590d\u5236\u4f9d\u8d56\u624b\u52a8<\/p>\n<div class=\"more-link\">\n\t\t\t\t <a href=\"https:\/\/yunyanglib.cn\/?p=667\" class=\"link-btn theme-btn\"><span>Read More <\/span> <i class=\"fa fa-caret-right\"><\/i><\/a>\n\t\t\t<\/div>\n","protected":false},"author":1,"featured_media":691,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[16],"class_list":["post-667","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=667"}],"version-history":[{"count":5,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions"}],"predecessor-version":[{"id":690,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions\/690"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/media\/691"}],"wp:attachment":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}