{"id":1090,"date":"2017-11-28T16:55:55","date_gmt":"2017-11-28T08:55:55","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=1090"},"modified":"2017-11-28T16:55:55","modified_gmt":"2017-11-28T08:55:55","slug":"mysql5-7-%e5%a4%8d%e5%88%b6%e6%a8%a1%e5%bc%8f%e7%9a%84%e6%a6%82%e5%bf%b5","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=1090","title":{"rendered":"MYSQL5.7 \u590d\u5236\u6a21\u5f0f\u7684\u6982\u5ff5"},"content":{"rendered":"<p>https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-mode-change-online-concepts.html<\/p>\n<p>\u4e3a\u4e86\u5b89\u5168\u7684\u914d\u7f6e\u590d\u5236\u6a21\u5f0f\uff0c\u5fc5\u987b\u8981\u61c2\u5f97\u4e00\u4e9b\u590d\u5236\u7684\u5173\u952e\u6982\u5ff5\u3002\u8fd9\u8282\u89e3\u91ca\u4e86\u8fd9\u4e9b\u6982\u5ff5\u5e76\u4e14\u5728\u4fee\u6539\u5728\u7ebf\u7cfb\u7edf\u4e4b\u524d\u5fc5\u987b\u8981\u77e5\u9053\u7684\u4e8b\u60c5\u3002<\/p>\n<p>\u7528\u4e8eMYSQL\u7684\u590d\u5236\u6a21\u5f0f\u4f9d\u8d56\u4e8e\u88ab\u8bb0\u5f55\u7684\u4e8b\u52a1\u6807\u8bc6\u7b26\u3002\u88ab\u590d\u5236\u7684\u4e8b\u52a1\u7c7b\u578b\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<ul>\n<li>GTID\u4e8b\u52a1\u7531GTID\u6807\u8bc6\uff0c\u5b83\u7684\u683c\u5f0fUUID:NUMBER\u3002\u6bcf\u4e00\u4e2a\u5728\u65e5\u5fd7\u4e2d\u8bb0\u5f55\u7684GTID\u4e8b\u52a1\uff0c\u90fd\u662f\u7531 <code class=\"literal\">Gtid_log_event<\/code>\u5f00\u5934\u3002GTID\u4e8b\u52a1\u5373\u53ef\u4ee5\u4f7f\u7528GTID\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6587\u4ef6\u540d\u548c\u4f4d\u7f6e\u5b9a\u4f4d\u3002<\/li>\n<li>\u533f\u540d\u4e8b\u52a1\u6ca1\u6709GTID\uff0c\u5e76\u4e14MYSQL\u4e2d\u7684\u6bcf\u4e2a\u533f\u540d\u4e8b\u52a1\u90fd\u4ee5 <code class=\"literal\">Anonymous_gtid_log_event<\/code> \u5f00\u5934\u8bb0\u5f55\u5230\u65e5\u5fd7\u4e2d\u3002<\/li>\n<\/ul>\n<p>\u5f53\u4f7f\u7528GTID\u4f60\u80fd\u4f7f\u7528auto-positioning\u529f\u80fd\u548c\u81ea\u52a8\u7684\u5931\u6548\u8f6c\u79fb\uff08fail-over\uff09,\u4e5f\u53ef\u4ee5\u4f7f\u7528<a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/gtid-functions.html#function_wait-for-executed-gtid-set\"><code class=\"literal\">WAIT_FOR_EXECUTED_GTID_SET()<\/code><\/a>, <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/server-system-variables.html#sysvar_session_track_gtids\"><code class=\"literal\">session_track_gtids<\/code><\/a>\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528 Performance Schema \u8868\u76d1\u63a7\u590d\u5236\u3002\u4f7f\u7528GTID\u65f6\u4e0d\u80fd\u4f7f\u7528 <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-slave.html#sysvar_sql_slave_skip_counter\"><code class=\"literal\">sql_slave_skip_counter<\/code><\/a>\uff0c\u800c\u4f7f\u7528\u7a7a\u4e8b\u52a1\u4ee3\u66ff\u3002<\/p>\n<p>\u5728relay log\u4e2d\u7684\u4e8b\u52a1\uff0c\u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u65f6\u53ef\u80fd\u6ca1\u4ee5\u4efb\u4f55\u7279\u5b9a\u4e8b\u52a1\u5f00\u5934\uff0c\u4f46\u662f\u5728\u5907\u673a\u4e0a\u91cd\u653e\u540e\u5e76\u88ab\u8bb0\u5f55\u5230\u5907\u673a\u4e0a\u7684binary log\u4e2d\u540e\u5b83\u4eec\u4f1a\u4ee5<code class=\"literal\">Anonymous_gtid_log_event<\/code>\u5f00\u5934\u3002<\/p>\n<p>\u8d26\u6237\u62e5\u6709SUPER\u6743\u9650\u53ef\u4ee5\u52a8\u6001\u7684\u8bbe\u7f6e<a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_mode\"><code class=\"literal\">gtid_mode<\/code><\/a> \u548c <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_enforce_gtid_consistency\"><code class=\"literal\">enforce_gtid_consistency<\/code><\/a> \u4e24\u4e2a\u53d8\u91cf\u3002\u5728\u4e4b\u524d\u7684\u7248\u672c\u4e2d\u8fd9\u4e24\u4e2a\u53d8\u91cf\u53ea\u80fd\u5728\u670d\u52a1\u542f\u52a8\u65f6\u8bbe\u7f6e\u3002\u5728\u6240\u6709\u7684\u7248\u672c\u4e2d <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_mode\"><code class=\"literal\">gtid_mode<\/code><\/a> \u53c2\u6570\u90fd\u4e0e\u662f\u5426\u4f7f\u7528GTID\u4fdd\u6301\u4e00\u81f4\u3002\u5f53gtid_mode=ON\u65f6\u4e0d\u53ef\u80fd\u590d\u5236\u533f\u540d\u4e8b\u52a1\uff0c\u800c\u5f53gtid_mod=OFF\u65f6\uff0c\u53ea\u6709\u533f\u540d\u4e8b\u52a1\u53ef\u4ee5\u88ab\u590d\u5236\u3002MYSQL5.7.6\u7684gtid_mode\u53d8\u91cf\u6709\u4e24\u4e2a\u989d\u5916\u7684\u72b6\u6001\uff0cOFF_PERMISSIVE\u548cON_PERMISSIVE\u3002\u5f53<a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_mode\"><code class=\"literal\">gtid_mode=OFF_PERMISSIVE<\/code><\/a> \u65f6\uff0c\u90a3\u4e48\u65b0\u7684\u4e8b\u52a1\u662f\u533f\u540d\u7684\u540c\u65f6\uff0c\u5141\u8bb8\u590d\u5236GTID\u6216\u533f\u540d\u4e8b\u52a1\u3002\u5f53 <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_mode\"><code class=\"literal\">gtid_mode=ON_PERMISSIVE<\/code><\/a> \u65f6\uff0c\u90a3\u4e48\u65b0\u7684\u4e8b\u52a1\u4f7f\u7528GTID\u7684\u540c\u65f6\uff0c\u5141\u8bb8\u590d\u5236GTID\u6216\u533f\u540d\u4e8b\u52a1\u3002\u8fd9\u610f\u5473\u7740\u670d\u52a1\u5668\u4f7f\u7528\u4e86\u533f\u540d\u548cGTID\u4e24\u79cd\u4e8b\u52a1\u3002\u4f8b\u5982\u4e00\u4e2a\u4e3b\u670d\u52a1\u5668\u4f7f\u7528\u4e86gtid_mode=ON\uff0c\u5907\u673a\u4f7f\u7528gtid_mode=ON_PERMISSIVE\u3002\u5bf9\u4e8egtid_mode\u7684\u6709\u6548\u503c\u987a\u5e8f\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>OFF<\/li>\n<li>OFF_PERMISSIVE<\/li>\n<li>ON_PERMISSIVE<\/li>\n<li>ON<\/li>\n<\/ul>\n<p>\u6539\u53d8gtid_mode\u72b6\u6001\u7684\u987a\u5e8f\u975e\u5e38\u91cd\u8981\uff0c\u53ea\u80fd\u6309\u4e0a\u9762\u7684\u987a\u5e8f\u4e00\u6b21\u4e00\u6b65\u7684\u6539\u53d8\u3002\u4f8b\u5982\uff0c\u5982\u679cgtid_mode\u5f53\u524d\u8bbe\u7f6e\u6210OFF_PERMISSIVE\uff0c\u5b83\u53ef\u80fd\u5728\u4e0b\u4e00\u6b21\u6539\u53d8\u6210OFF\u6216ON_PERMISSIVE\uff0c\u4f46\u662f\u4e0d\u80fd\u8bbe\u7f6e\u6210ON\u3002\u8fd9\u4e3a\u4e86\u4fdd\u8bc1\u4ece\u533f\u540d\u4e8b\u52a1\u5728\u7ebf\u6539\u53d8\u5230GTID\u4e8b\u52a1\uff0c\u80fd\u88ab\u670d\u52a1\u5668\u6b63\u786e\u5904\u7406\u3002\u5f53gtid_mode\u7684\u6a21\u5f0f\u5728ON\u548cOFF\u4e4b\u95f4\u5207\u6362\u65f6\uff0cGTID\u7684\u72b6\u6001\uff08\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_executed\"><code class=\"literal\">gtid_executed<\/code><\/a> \u7684\u503c\uff09\u662f\u8fde\u7eed\u7684\u3002\u8fd9\u786e\u4fddGTID\u96c6\u5df2\u7ecf\u88ab\u670d\u52a1\u5668\u5e94\u7528\uff0c\u65e0\u8bbagtid_mode\u7684\u503c\u662f\u4ec0\u4e48\u3002<\/p>\n<p>\u4f5c\u4e3aMYSQL5.7.6\u6539\u53d8\u7684\u4e00\u90e8\u5206\uff0c\u5173\u8054\u5230GTID\u7684\u5b57\u6bb5\u5df2\u7ecf\u88ab\u4fee\u6539\uff0c\u4ee5\u81f3\u4e8e\u65e0\u8bbagtid_mode\u5f53\u524d\u7684\u503c\u88ab\u9009\u62e9\u6210\u4ec0\u4e48\uff0c\u90fd\u80fd\u663e\u793a\u6b63\u786e\u7684\u4fe1\u606f\u3002\u8fd9\u610f\u5473\u7740\u50cf\u662f\u5728 <a class=\"link\" title=\"25.11.11.2\u00a0The replication_connection_status Table\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-connection-status-table.html\"><code class=\"literal\">replication_connection_status<\/code><\/a> Performance Schema\u8868\u4e2d\u7684<a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_executed\"><code class=\"literal\">gtid_executed<\/code><\/a>, <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_purged\"><code class=\"literal\">gtid_purged<\/code><\/a>, <code class=\"literal\">RECEIVED_TRANSACTION_SET<\/code> \u663e\u793aGTID\u96c6\u7684\u5b57\u6bb5\uff0c\u548c <a class=\"link\" title=\"13.7.5.34\u00a0SHOW SLAVE STATUS Syntax\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/show-slave-status.html\"><code class=\"literal\">SHOW SLAVE STATUS<\/code><\/a> \u663e\u793a\u76f8\u5173GTID\u7ed3\u679c\u7684\u5b57\u6bb5\uff0c\u5f53\u6ca1\u6709\u63d0\u4f9bGTID\u65f6\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002\u5f53\u6ca1\u4f7f\u7528GTID\u4e8b\u52a1\u65f6\uff0c\u663e\u793a\u5355\u6761GTID\u7684\u5b57\u6bb5\u73b0\u5728\u663e\u793aANONYMOUS\u3002\u5982\u5728 <a class=\"link\" title=\"25.11.11.6\u00a0The replication_applier_status_by_worker Table\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-applier-status-by-worker-table.html\"><code class=\"literal\">replication_applier_status_by_worker<\/code><\/a> Performance Schema\u8868\u4e2d\u7684CURRENT_TRANSCTION\u3002<\/p>\n<p>\u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u4f7f\u7528gtid_mode=ON\u63d0\u4f9b\u4f7f\u7528auto-positoning\u7684\u80fd\u529b\uff0c\u65b9\u6cd5\u662f\u5728\u914d\u7f6e\u65f6\u4f7f\u7528<code>CHANGE MASTER TO MASTER_AUTO_POSITION = 1;<\/code>\u8bed\u53e5\u3002\u590d\u5236\u7684\u62d3\u6251\u7ed3\u6784\u5f71\u54cd\u662f\u5426\u5f00\u542fauto-positioning\uff0c\u8fd9\u4e2a\u529f\u80fd\u4f9d\u8d56\u4e8eGTID\u548c\u662f\u5426\u517c\u5bb9\u533f\u540d\u4e8b\u52a1\u3002\u5982\u679cauto-positioning\u5f00\u542f\u5e76\u4e14\u4f7f\u7528\u4e86\u533f\u540d\u4e8b\u52a1\uff0c\u90a3\u4e48\u4f1a\u53d1\u751f\u9519\u8bef\u3002\u5f3a\u70c8\u5efa\u8bae\u5728\u4f7f\u7528auto-positioning\u4e4b\u524d\uff0c\u5148\u786e\u8ba4\u6ca1\u6709\u4f7f\u7528\u533f\u540d\u4e8b\u52a1\uff08 see <a class=\"xref\" title=\"16.1.5.2\u00a0Enabling GTID Transactions Online\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-mode-change-online-enable-gtids.html\">Section\u00a016.1.5.2, \u201cEnabling GTID Transactions Online\u201d<\/a>\uff09\u3002\u5728\u4e3b\u4ece\u670d\u52a1\u5668\u4e0agtid_mode\u548cauto-positioning\u7684\u517c\u5bb9\u8868\u5982\u4e0b\u6240\u793a\uff0c\u5728\u8868\u4e2dgtid_mode\u6c34\u5e73\u663e\u793a\u7684\u662f\u4e3b\u670d\u52a1\u5668\uff0c\u4ece\u670d\u52a1\u5668\u7684gtid_mode\u5782\u76f4\u663e\u793a\uff1a<\/p>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td>MASTER\/SLAVE GTID_MODE<\/td>\n<td>OFF<\/td>\n<td>OFF_PERMISSIVE<\/td>\n<td>ON_PERMISSIVE<\/td>\n<td>ON<\/td>\n<\/tr>\n<tr>\n<td>OFF<\/td>\n<td>Y<\/td>\n<td>Y<\/td>\n<td>N<\/td>\n<td>N<\/td>\n<\/tr>\n<tr>\n<td>OFF_PERMISSIVE<\/td>\n<td>Y<\/td>\n<td>Y<\/td>\n<td>Y<\/td>\n<td>Y*<\/td>\n<\/tr>\n<tr>\n<td>ON_PERMISSIVE<\/td>\n<td>Y<\/td>\n<td>Y<\/td>\n<td>Y<\/td>\n<td>Y*<\/td>\n<\/tr>\n<tr>\n<td>ON<\/td>\n<td>N<\/td>\n<td>N<\/td>\n<td>Y<\/td>\n<td>Y*<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728\u4e0a\u9762\u7684\u8868\u4e2d\uff1a<\/p>\n<ul>\n<li>Y:\u4ee3\u8868\u4e3b\u4ece\u670d\u52a1\u5668\u7684gtid_mode\u662f\u517c\u5bb9\u7684\u3002<\/li>\n<li>N:\u4ee3\u8868\u4e3b\u4ece\u670d\u52a1\u5668\u7684gtid_mode\u662f\u4e0d\u517c\u5bb9\u7684\u3002<\/li>\n<li>*\u53ef\u4ee5\u4f7f\u7528auto-positioning\u3002<\/li>\n<\/ul>\n<p>\u5f53\u524d\u9009\u62e9\u7684gtid_mode\u540c\u6837\u80fd\u5f71\u54cd <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-options-gtids.html#sysvar_gtid_next\"><code class=\"literal\">gtid_next<\/code><\/a>\u00a0 \u53d8\u91cf\u3002\u4e0b\u9762\u7684\u8868\u663e\u793a\u4e86\u670d\u52a1\u5668\u4e0a\u4e0d\u540c\u7684gtid_mode\u548cgtid_next\u503c\u7684\u884c\u4e3a\uff1a<\/p>\n<p>ON_PERMISSIVENEW GTIDANONYMOUSANONYMOUSUUID:NUMBER<\/p>\n<table>\n<tbody>\n<tr>\n<td>gtid_next<\/td>\n<td>AUTOMATIC BINARY LOG ON<\/td>\n<td>AUTOMATIC BINARY LOG OFF<\/td>\n<td>ANONYMOUS<\/td>\n<td>UUID:NUMBER<\/td>\n<\/tr>\n<tr>\n<td>OFF<\/td>\n<td>ANONYMOUS<\/td>\n<td>ANONYMOUS<\/td>\n<td>ANONYMOUS<\/td>\n<td>ERROR<\/td>\n<\/tr>\n<tr>\n<td>OFF_PERMISSIVE<\/td>\n<td>ANONYMOUS<\/td>\n<td>ANONYMOUS<\/td>\n<td>ANONYMOUS<\/td>\n<td>UUID:NUMBER<\/td>\n<\/tr>\n<tr>\n<td>ON<\/td>\n<td>NEW GTID<\/td>\n<td>ANONYMOUS<\/td>\n<td>ERROR<\/td>\n<td>UUID:NUMBER<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728\u4e0a\u9762\u7684\u8868\u4e2d\uff1a<\/p>\n<ul>\n<li>ANONYMOUS:\u4ea7\u751f\u533f\u540d\u4e8b\u52a1\u3002<\/li>\n<li>ERROR\uff1a\u4ea7\u751f\u9519\u8bef\u5e76\u4e14\u4f1a\u5728\u6267\u884cSET GTID_NEXT\u65f6\u5931\u8d25\u3002<\/li>\n<li>UUID:NUMBER:\u4ee3\u4e00\u4e2a\u6307\u5b9a\u7684UUID:NUMBER\u7684GTID\u3002<\/li>\n<li>NEW GTID\uff1a\u81ea\u52a8\u4ea7\u751f\u4e00\u4e2aGTID\u3002<\/li>\n<\/ul>\n<p>\u5f53binary log\u5173\u95ed\u5e76\u4e14gtid_next\u8bbe\u7f6e\u6210AUTOMATIC\u65f6\uff0c\u90a3\u4e48\u6ca1\u6709GTID\u4ea7\u751f\u3002\u8fd9\u4e2a\u884c\u4e3a\u548c\u4e4b\u524d\u7684\u7248\u672c\u4e00\u81f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/replication-mode-change-online-concepts&#8230;.<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=1090\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-1090","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1090"}],"version-history":[{"count":3,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1090\/revisions"}],"predecessor-version":[{"id":1093,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1090\/revisions\/1093"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}