{"id":415,"date":"2022-07-07T11:29:14","date_gmt":"2022-07-07T03:29:14","guid":{"rendered":"https:\/\/frogvps.com\/?p=415"},"modified":"2022-07-07T11:29:15","modified_gmt":"2022-07-07T03:29:15","slug":"mysql%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%e6%95%b0%e6%8d%ae%e4%b8%8d%e4%b8%80%e8%87%b4%e7%9a%84%e5%8e%9f%e5%9b%a0%e5%92%8c%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/frogvps.com\/?p=415","title":{"rendered":"MYSQL\u4e3b\u4ece\u590d\u5236\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u539f\u56e0<\/h2>\n\n\n\n<p>\u9020\u6210MYSQL\u4e3b\u4ece\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u53ef\u80fd\u539f\u56e0\u6c47\u603b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Master\u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u683c\u5f0f\uff08binlog_format\uff09\u9519\u8bef\u7684\u8bbe\u7f6e\u6210\u4e86statement\uff0c\u540c\u6b65\u5230slave\u65f6\u5f15\u8d77\u7684\u4e0d\u4e00\u81f4<\/li><li>Master\u5728\u6570\u636e\u66f4\u6539\u524d\u6267\u884c\u8fc7set sql_log_bin=0\uff0c\u5bfc\u81f4\u4e8c\u8fdb\u5236\u65e5\u5fd7\u6ca1\u6709\u88ab\u8bb0\u5f55\uff0cslave\u63a5\u6536\u4e0d\u5230\u65e5\u5fd7<\/li><li>Slave\u672a\u8bbe\u7f6e\u53ea\u8bfb\uff0c\u7528\u6237\u8bef\u64cd\u4f5c\u5199\u5165\u6570\u636e<\/li><li>Master\u6216slave\u610f\u5916\u5b95\u673a\uff0c\u5b95\u673a\u53ef\u80fd\u4f1a\u9020\u6210binlog\u6216\u8005relaylog\u6587\u4ef6\u51fa\u73b0\u635f\u574f\uff0c\u5bfc\u81f4\u4e3b\u4ece\u4e0d\u4e00\u81f4<\/li><li>\u4e3b\u4ece\u5b9e\u4f8b\u7248\u672c\u4e0d\u4e00\u81f4\uff0c\u7279\u522b\u662f\u9ad8\u7248\u672c\u662f\u4e3b\uff0c\u4f4e\u7248\u672c\u4e3a\u4ece\u7684\u60c5\u51b5\u4e0b\uff0c\u4e3b\u6570\u636e\u5e93\u4e0a\u9762\u652f\u6301\u7684\u529f\u80fd\uff0c\u4ece\u6570<br>\u636e\u5e93\u4e0a\u9762\u53ef\u80fd\u4e0d\u652f\u6301\u8be5\u529f\u80fd<\/li><li>MySQL\u81ea\u8eabbug\u5bfc\u81f4<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4fee\u590d\u65b9\u6848<\/h2>\n\n\n\n<p>MYSQL\u4e3b\u4ece\u6570\u636e\u4e0d\u4e00\u81f4\uff0c\u53ef\u4ee5\u628a\u6574\u4e2a\u4ece\u670d\u52a1\u5668\u7684\u6570\u636e\u91cd\u65b0\u5907\u4efd\u8fd8\u539f\uff0c\u7136\u540e\u91cd\u65b0\u5f00\u59cb\u540c\u6b65\u3002\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u7b80\u5355\uff0c\u4f46\u662f\u6062\u590d\u65f6\u95f4\u592a\u957f\uff0c\u4ece\u8282\u70b9\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\u4e0d\u80fd\u627f\u62c5\u67e5\u8be2\u64cd\u4f5c\u3002\u5982\u679c\u4ece\u8282\u70b9\u53ea\u6709\u51e0\u5f20\u8868\u7684\u6570\u636e\u548c\u4e3b\u8282\u70b9\u4e0d\u4e00\u81f4\uff0c\u53ef\u4ee5\u5148\u6682\u505c\u4ece\u4e3b\u8282\u70b9\u590d\u5236\u6570\u636e\uff0c\u624b\u5de5\u91cd\u5efa\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u8868\uff0c\u7136\u540e\u91cd\u65b0\u5f00\u542f\u590d\u5236\u3002<\/p>\n\n\n\n<p><strong>\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u6709\u4e00\u5bf9\u6b63\u5728\u8fd0\u884c\u7684\u4e3b\u4ece\u590d\u5236\u670d\u52a1\u5668\uff0c\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u53d1\u73b0testdb\u6570\u636e\u5e93\u4e2d\u6709A\u3001B\u3001C\u4e09\u5f20\u8868\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n\n\n\n<p>\u4fee\u590d\u6570\u636e\uff0c\u5355\u72ec\u91cd\u5efaA\u3001B\u3001C<\/p>\n\n\n\n<p>1.\u4ece\u670d\u52a1\u5668\u6682\u505c\u590d\u5236\uff0c\u5047\u8bbe\u65f6\u95f4\u70b9\u662fT1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stop replica;<\/code><\/pre>\n\n\n\n<p>2.\u4e3b\u670d\u52a1\u5668\u5355\u72ec\u5907\u4efd\u8fd9\u4e09\u5f20\u8868\uff0c\u4f1a\u7ecf\u8fc7\u4e00\u6bb5\u65f6\u95f4\uff0c\u5047\u8bbe\u65f6\u95f4\u70b9\u662fT2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -uroot -p  --single-transaction --master-data=2 testdb A B C &gt; A_B_C.sql<\/code><\/pre>\n\n\n\n<p>3.\u67e5\u770bA_B_C.sql\u6587\u4ef6\uff0c\u627e\u5230 &#8220;CHANGE MASTER TO&#8221; \u8fd9\u4e00\u884c\u6ce8\u91ca\uff0c\u8bb0\u5f55\u4e0b\u65e5\u5fd7\u6587\u4ef6\u540d\u548cPOS\uff0c\u4e5f\u5c31\u662fT2\u65f6\u95f4\u70b9\u65e5\u5fd7\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MASTER_LOG_FILE=binlog.00000\n\nMASTER_LOG_POS=xxx<\/code><\/pre>\n\n\n\n<p>4.\u628aA_B_C.sql\u6587\u4ef6\u62f7\u8d1d\u5230\u4ece\u670d\u52a1\u5668\uff0c\u5148\u4e0d\u4f7f\u7528\u8fd9\u4e2a\u5907\u4efd\uff0c\u628a\u4ece\u6570\u636e\u5e93\u7ee7\u7eed\u540c\u6b65\u5230\u521a\u624d\u8bb0\u5f55\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u65f6\u95f4\u70b9T2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>start replica until MASTERLOGFILE='binlog.00000x',MASTERLOGPOS=xxx;<\/code><\/pre>\n\n\n\n<p>5.\u5355\u72ec\u8fd8\u539fA\u3001B\u3001C\u8868\uff0c\u8fd9\u65f6\u5019\u6240\u6709\u7684\u6570\u636e\u90fd\u6b63\u786e\u8fd8\u539f\u4e86\uff0c\u53ea\u662f\u6570\u636e\u53ea\u66f4\u65b0\u5230\u4e86T2\u8fd9\u4e2a\u65f6\u95f4\u70b9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -uroot -p testdb\nset sql_bin_log=0;\nsource A_B_C.sql\nset sql_bin_log=1;<\/code><\/pre>\n\n\n\n<p>6.\u7136\u540e\u53ea\u8981\u5728\u4ece\u8282\u70b9\u7ee7\u7eed\u5f00\u542f\u590d\u5236\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>start replica;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u907f\u514d<\/h2>\n\n\n\n<p>MYSQL\u5982\u4f55\u907f\u514d\u4e3b\u4ece\u6570\u636e\u4e0d\u4e00\u81f4<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e3b\u8282\u70b9binlog_format\u8bbe\u7f6e\u4e3aROW<\/li><li>\u4e3b\u4ece\u6570\u636e\u5e93\u4fdd\u6301\u7248\u672c\u4e00\u81f4<\/li><li>\u4e3b\u5e93\u505a\u597d\u8d26\u53f7\u6743\u9650\u628a\u63a7\uff0c\u4e0d\u53ef\u4ee5\u6267\u884cset sql_log_bin=0<\/li><li>\u4ece\u5e93\u5f00\u542f\u53ea\u8bfb\uff0c\u9632\u6b62\u8ba4\u4e3a\u5199\u5165<\/li><li>\u5b9a\u671f\u8fdb\u884c\u4e3b\u4ece\u4e00\u81f4\u6027\u68c0\u9a8c<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u56e0 \u9020\u6210MYSQL\u4e3b\u4ece\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u53ef\u80fd\u539f\u56e0\u6c47\u603b\uff1a Master\u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u683c\u5f0f\uff08binlog_format\uff09\u9519\u8bef\u7684\u8bbe\u7f6e\u6210\u4e86statement\uff0c\u540c\u6b65\u5230slave\u65f6\u5f15\u8d77\u7684\u4e0d\u4e00\u81f4 Master\u5728\u6570\u636e\u66f4\u6539\u524d\u6267\u884c\u8fc7set sql_log_bin=0&#8230;<\/p>\n","protected":false},"author":1,"featured_media":283,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[36],"topic":[],"class_list":["post-415","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-35","tag-mysql"],"_links":{"self":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=415"}],"version-history":[{"count":2,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/415\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/415\/revisions\/417"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/media\/283"}],"wp:attachment":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=415"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}