{"id":5451,"date":"2024-11-14T11:07:57","date_gmt":"2024-11-14T03:07:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5451\/"},"modified":"2024-11-14T11:07:57","modified_gmt":"2024-11-14T03:07:57","slug":"mysql%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8gtid","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5451\/","title":{"rendered":"mysql\u600e\u4e48\u4f7f\u7528gtid"},"content":{"rendered":"<blockquote><p>\n  \u542f\u7528 mysql \u7684 gtid \u6b65\u9aa4\uff1a1. \u542f\u7528 gtid \u7acb\u5373\u6a21\u5f0f\uff1b2. \u91cd\u542f mysql\uff1b3. \u914d\u7f6e\u526f\u672c\uff1b4. \u66f4\u65b0\u590d\u5236\u7528\u6237\u6743\u9650\uff1b5. \u542f\u52a8\u590d\u5236\u3002gtid \u7528\u4e8e\u8bc6\u522b\u548c\u8ddf\u8e2a mysql \u4e8b\u52a1\u5728\u590d\u5236\u7ec4\u4e2d\u7684\u6267\u884c\u987a\u5e8f\uff0c\u786e\u4fdd\u526f\u672c\u4e0a\u4e8b\u52a1\u7684\u987a\u5e8f\u4e0e\u4e3b\u670d\u52a1\u5668\u76f8\u540c\uff0c\u4ee5\u89e3\u51b3\u590d\u5236\u8fc7\u7a0b\u4e2d\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052814092597195.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u4f7f\u7528gtid\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u4f7f\u7528gtid\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u7684 GTID<\/strong><\/p>\n<p><strong>GTID \u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>\u5168\u7403\u4e8b\u52a1\u6807\u8bc6\u7b26 (GTID) \u662f\u4e00\u79cd\u673a\u5236\uff0c\u7528\u4e8e\u8bc6\u522b\u548c\u8ddf\u8e2a MySQL \u4e8b\u52a1\u5728\u590d\u5236\u7ec4\u4e2d\u7684\u6267\u884c\u987a\u5e8f\u3002GTID \u89e3\u51b3\u4e86\u590d\u5236\u8fc7\u7a0b\u4e2d\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\uff0c\u786e\u4fdd\u526f\u672c\u4e0a\u4e8b\u52a1\u7684\u987a\u5e8f\u4e0e\u4e3b\u670d\u52a1\u5668\u76f8\u540c\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 GTID<\/strong><\/p>\n<p>\u8981\u4f7f\u7528 GTID\uff0c\u9700\u8981\u542f\u7528\u5b83\u5e76\u914d\u7f6e\u590d\u5236\u7ec4\u4e2d\u7684\u6240\u6709\u670d\u52a1\u5668\u3002\u4ee5\u4e0b\u662f\u542f\u7528 GTID \u7684\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u542f\u7528 GTID \u7acb\u5373\u6a21\u5f0f\uff1a<\/strong>\u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<pre>SET GLOBAL gtid_mode=ON;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li> <strong>\u91cd\u542f MySQL\uff1a<\/strong>\u91cd\u542f MySQL \u670d\u52a1\u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/li>\n<li> <strong>\u914d\u7f6e\u526f\u672c\uff1a<\/strong>\u5728\u526f\u672c\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u5b83\u4eec\u914d\u7f6e\u4e3a\u4ece\u4e3b\u670d\u52a1\u5668\u590d\u5236\uff1a<\/li>\n<\/ol>\n<pre>CHANGE MASTER TO MASTER_HOST='&lt;\u4e3b\u670d\u52a1\u5668 IP&gt;',\nMASTER_USER='&lt;\u590d\u5236\u7528\u6237&gt;',\nMASTER_PASSWORD='&lt;\u590d\u5236\u5bc6\u7801&gt;',\nMASTER_AUTO_POSITION=1,\nMASTER_USE_GTID=ON;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li> <strong>\u66f4\u65b0\u590d\u5236\u7528\u6237\u6743\u9650\uff1a<\/strong>\u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u6dfb\u52a0 REPLICATION SLAVE \u6743\u9650\u7ed9\u590d\u5236\u7528\u6237\u3002<\/li>\n<li> <strong>\u542f\u52a8\u590d\u5236\uff1a<\/strong>\u5728\u526f\u672c\u4e0a\u6267\u884c START SLAVE \u547d\u4ee4\u4ee5\u542f\u52a8\u590d\u5236\u3002<\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u542f\u7528 GTID \u4e4b\u524d\uff0c\u8bf7\u5907\u4efd\u6570\u636e\u3002<\/li>\n<li>\u6240\u6709\u590d\u5236\u7ec4\u4e2d\u7684\u670d\u52a1\u5668\u5fc5\u987b\u6267\u884c\u76f8\u540c\u7684 GTID \u6a21\u5f0f\u3002<\/li>\n<li>GTID \u4e00\u65e6\u542f\u7528\u540e\uff0c\u5c31\u65e0\u6cd5\u518d\u7981\u7528\u3002<\/li>\n<li>\u8bf7\u52a1\u5fc5\u4fdd\u6301\u526f\u672c\u7684 GTID \u6267\u884c\u4f4d\u7f6e\u4e0e\u4e3b\u670d\u52a1\u5668\u540c\u6b65\u3002<\/li>\n<li>\u5982\u679c GTID \u51fa\u73b0\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528 RESET SLAVE TO \u547d\u4ee4\u6765\u91cd\u7f6e\u526f\u672c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u4f7f\u7528gtid\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u542f\u7528 mysql \u7684 gtid \u6b65\u9aa4\uff1a1. \u542f\u7528 gtid \u7acb\u5373\u6a21\u5f0f\uff1b2. \u91cd\u542f mysql\uff1b3. \u914d\u7f6e\u526f\u672c\uff1b4. \u66f4\u65b0\u590d\u5236\u7528\u6237\u6743\u9650\uff1b5. \u542f\u52a8\u590d\u5236\u3002gtid \u7528\u4e8e\u8bc6\u522b\u548c\u8ddf\u8e2a mysql \u4e8b\u52a1\u5728\u590d\u5236\u7ec4\u4e2d\u7684\u6267\u884c\u987a\u5e8f\uff0c\u786e\u4fdd\u526f\u672c\u4e0a\u4e8b\u52a1\u7684\u987a\u5e8f\u4e0e\u4e3b\u670d\u52a1\u5668\u76f8\u540c\uff0c\u4ee5\u89e3\u51b3\u590d\u5236\u8fc7\u7a0b\u4e2d\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002 \u5982\u4f55\u4f7f\u7528 MySQL \u7684 GTID GTID \u662f\u4ec0\u4e48\uff1f \u5168\u7403\u4e8b\u52a1\u6807\u8bc6\u7b26 (GTID) \u662f\u4e00\u79cd\u673a\u5236\uff0c\u7528\u4e8e\u8bc6\u522b\u548c\u8ddf\u8e2a MySQL \u4e8b\u52a1\u5728\u590d\u5236\u7ec4\u4e2d\u7684\u6267\u884c\u987a\u5e8f\u3002GTID \u89e3\u51b3\u4e86\u590d\u5236\u8fc7\u7a0b\u4e2d\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\uff0c\u786e\u4fdd\u526f\u672c\u4e0a\u4e8b\u52a1\u7684\u987a\u5e8f\u4e0e\u4e3b\u670d\u52a1\u5668\u76f8\u540c\u3002 \u5982\u4f55\u4f7f\u7528 GTID \u8981\u4f7f\u7528 GTID\uff0c\u9700\u8981\u542f\u7528\u5b83\u5e76\u914d\u7f6e\u590d\u5236\u7ec4\u4e2d\u7684\u6240\u6709\u670d\u52a1\u5668\u3002\u4ee5\u4e0b\u662f\u542f\u7528 GTID \u7684\u6b65\u9aa4\uff1a \u542f\u7528 GTID \u7acb\u5373\u6a21\u5f0f\uff1a\u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a SET GLOBAL gtid_mode=ON; \u767b\u5f55\u540e\u590d\u5236 \u91cd\u542f MySQL\uff1a\u91cd\u542f MySQL \u670d\u52a1\u4ee5\u5e94\u7528\u66f4\u6539\u3002 \u914d\u7f6e\u526f\u672c\uff1a\u5728\u526f\u672c\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u5b83\u4eec\u914d\u7f6e\u4e3a\u4ece\u4e3b\u670d\u52a1\u5668\u590d\u5236\uff1a CHANGE MASTER TO MASTER_HOST='&lt;\u4e3b\u670d\u52a1\u5668 IP&gt;&#8217;, MASTER_USER='&lt;\u590d\u5236\u7528\u6237&gt;&#8217;, MASTER_PASSWORD='&lt;\u590d\u5236\u5bc6\u7801&gt;&#8217;, MASTER_AUTO_POSITION=1, MASTER_USE_GTID=ON; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5451","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5451"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5451\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}