{"id":152473,"date":"2024-11-01T23:19:24","date_gmt":"2024-11-01T15:19:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/152473\/"},"modified":"2024-11-01T23:19:25","modified_gmt":"2024-11-01T15:19:25","slug":"%e6%9f%a5%e7%9c%8b-mysql-%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/152473\/","title":{"rendered":"\u67e5\u770b MySQL \u4e8c\u9032\u5236\u65e5\u8a8c\u7684\u65b9\u6cd5"},"content":{"rendered":"<h1 id=\"%e6%9f%a5%e7%9c%8b-mysql-%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c%e7%9a%84%e6%96%b9%e6%b3%95-SVykHsREUG\">\u67e5\u770b MySQL \u4e8c\u9032\u5236\u65e5\u8a8c\u7684\u65b9\u6cd5<\/h1>\n<p>MySQL \u7684\u4e8c\u9032\u5236\u65e5\u8a8c\uff08Binary Log\uff09\u662f\u4e00\u500b\u91cd\u8981\u7684\u529f\u80fd\uff0c\u4e3b\u8981\u7528\u65bc\u8a18\u9304\u6240\u6709\u66f4\u6539\u6578\u64da\u7684\u64cd\u4f5c\u3002\u9019\u4e9b\u65e5\u8a8c\u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u6578\u64da\u6062\u5fa9\uff0c\u9084\u53ef\u4ee5\u7528\u65bc\u8907\u88fd\u548c\u5be9\u8a08\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u67e5\u770b MySQL \u7684\u4e8c\u9032\u5236\u65e5\u8a8c\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u547d\u4ee4\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-mysql-%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c%ef%bc%9f-SVykHsREUG\">\u4ec0\u9ebc\u662f MySQL \u4e8c\u9032\u5236\u65e5\u8a8c\uff1f<\/h2>\n<p>MySQL \u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u662f\u4e00\u7a2e\u8a18\u9304\u6240\u6709\u66f4\u6539\u6578\u64da\u7684\u64cd\u4f5c\u7684\u65e5\u8a8c\u6587\u4ef6\u3002\u9019\u4e9b\u64cd\u4f5c\u5305\u62ec INSERT\u3001UPDATE \u548c DELETE \u7b49\u3002\u4e8c\u9032\u5236\u65e5\u8a8c\u7684\u4e3b\u8981\u7528\u9014\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u6578\u64da\u6062\u5fa9\uff1a\u5728\u6578\u64da\u640d\u58de\u6216\u4e1f\u5931\u7684\u60c5\u6cc1\u4e0b\uff0c\u53ef\u4ee5\u901a\u904e\u4e8c\u9032\u5236\u65e5\u8a8c\u6062\u5fa9\u6578\u64da\u3002<\/li>\n<li>\u8907\u88fd\uff1a\u5728\u4e3b\u5f9e\u8907\u88fd\u67b6\u69cb\u4e2d\uff0c\u5f9e\u4f3a\u670d\u5668\u53ef\u4ee5\u901a\u904e\u4e8c\u9032\u5236\u65e5\u8a8c\u7372\u53d6\u4e3b\u4f3a\u670d\u5668\u7684\u6578\u64da\u8b8a\u66f4\u3002<\/li>\n<li>\u5be9\u8a08\uff1a\u53ef\u4ee5\u7528\u65bc\u8ffd\u8e64\u6578\u64da\u7684\u8b8a\u66f4\u6b77\u53f2\uff0c\u4fbf\u65bc\u5be9\u8a08\u548c\u5408\u898f\u6027\u6aa2\u67e5\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b-mysql-%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c-SVykHsREUG\">\u5982\u4f55\u67e5\u770b MySQL \u4e8c\u9032\u5236\u65e5\u8a8c<\/h2>\n<p>\u8981\u67e5\u770b MySQL \u7684\u4e8c\u9032\u5236\u65e5\u8a8c\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fdd MySQL \u4f3a\u670d\u5668\u5df2\u7d93\u555f\u7528\u4e8c\u9032\u5236\u65e5\u8a8c\u529f\u80fd\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u6b65\u9a5f\u4f86\u6aa2\u67e5\u548c\u67e5\u770b\u4e8c\u9032\u5236\u65e5\u8a8c\uff1a<\/p>\n<h3 id=\"1-%e6%aa%a2%e6%9f%a5%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c%e6%98%af%e5%90%a6%e5%95%9f%e7%94%a8-SVykHsREUG\">1. \u6aa2\u67e5\u4e8c\u9032\u5236\u65e5\u8a8c\u662f\u5426\u555f\u7528<\/h3>\n<p>\u53ef\u4ee5\u901a\u904e\u57f7\u884c\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u6aa2\u67e5\u4e8c\u9032\u5236\u65e5\u8a8c\u662f\u5426\u555f\u7528\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'log_bin';<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de\u7684\u503c\u70ba ON\uff0c\u5247\u8868\u793a\u4e8c\u9032\u5236\u65e5\u8a8c\u5df2\u555f\u7528\u3002\u5982\u679c\u70ba OFF\uff0c\u5247\u9700\u8981\u5728 MySQL \u914d\u7f6e\u6587\u4ef6\u4e2d\u555f\u7528\u5b83\uff0c\u901a\u5e38\u662f\u5728 my.cnf \u6216 my.ini \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>[mysqld]\nlog_bin = mysql-bin<\/code><\/pre>\n<h3 id=\"2-%e6%9f%a5%e7%9c%8b%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c%e6%96%87%e4%bb%b6-SVykHsREUG\">2. \u67e5\u770b\u4e8c\u9032\u5236\u65e5\u8a8c\u6587\u4ef6<\/h3>\n<p>\u4e8c\u9032\u5236\u65e5\u8a8c\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc MySQL \u6578\u64da\u76ee\u9304\u4e2d\uff0c\u6587\u4ef6\u540d\u4ee5 mysql-bin \u958b\u982d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5217\u51fa\u6240\u6709\u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u6587\u4ef6\uff1a<\/p>\n<pre><code>SHOW BINARY LOGS;<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u6240\u6709\u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u6587\u4ef6\u53ca\u5176\u5927\u5c0f\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-mysqlbinlog-%e5%b7%a5%e5%85%b7%e6%9f%a5%e7%9c%8b%e6%97%a5%e8%aa%8c%e5%85%a7%e5%ae%b9-SVykHsREUG\">3. \u4f7f\u7528 mysqlbinlog \u5de5\u5177\u67e5\u770b\u65e5\u8a8c\u5167\u5bb9<\/h3>\n<p>MySQL \u63d0\u4f9b\u4e86\u4e00\u500b\u540d\u70ba mysqlbinlog \u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4f86\u67e5\u770b\u4e8c\u9032\u5236\u65e5\u8a8c\u7684\u5167\u5bb9\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>mysqlbinlog \/path\/to\/mysql-bin.000001<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u6307\u5b9a\u4e8c\u9032\u5236\u65e5\u8a8c\u6587\u4ef6\u7684\u5167\u5bb9\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u9078\u9805\u4f86\u904e\u6ffe\u8f38\u51fa\uff1a<\/p>\n<ul>\n<li><code>--start-datetime<\/code>\uff1a\u6307\u5b9a\u958b\u59cb\u6642\u9593\u3002<\/li>\n<li><code>--stop-datetime<\/code>\uff1a\u6307\u5b9a\u7d50\u675f\u6642\u9593\u3002<\/li>\n<li><code>--database<\/code>\uff1a\u6307\u5b9a\u8981\u67e5\u770b\u7684\u6578\u64da\u5eab\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u8981\u67e5\u770b\u7279\u5b9a\u6642\u9593\u7bc4\u570d\u5167\u7684\u65e5\u8a8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>mysqlbinlog --start-datetime=\"2023-01-01 00:00:00\" --stop-datetime=\"2023-01-02 00:00:00\" \/path\/to\/mysql-bin.000001<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-SVykHsREUG\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u67e5\u770b\u548c\u7ba1\u7406\u4e8c\u9032\u5236\u65e5\u8a8c\u6642\uff0c\u61c9\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u5b9a\u671f\u6e05\u7406\uff1a\u4e8c\u9032\u5236\u65e5\u8a8c\u6703\u4f54\u7528\u78c1\u789f\u7a7a\u9593\uff0c\u61c9\u5b9a\u671f\u6e05\u7406\u4e0d\u518d\u9700\u8981\u7684\u65e5\u8a8c\u6587\u4ef6\u3002<\/li>\n<li>\u5099\u4efd\uff1a\u5728\u9032\u884c\u91cd\u8981\u64cd\u4f5c\u4e4b\u524d\uff0c\u5efa\u8b70\u5099\u4efd\u4e8c\u9032\u5236\u65e5\u8a8c\uff0c\u4ee5\u9632\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<li>\u6b0a\u9650\uff1a\u78ba\u4fdd\u57f7\u884c mysqlbinlog \u7684\u7528\u6236\u64c1\u6709\u8db3\u5920\u7684\u6b0a\u9650\u4f86\u8a2a\u554f\u65e5\u8a8c\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-SVykHsREUG\">\u7e3d\u7d50<\/h2>\n<p>MySQL \u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u9032\u884c\u6578\u64da\u6062\u5fa9\u3001\u8907\u88fd\u548c\u5be9\u8a08\u3002\u901a\u904e\u672c\u6587\u4ecb\u7d39\u7684\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u67e5\u770b\u548c\u7ba1\u7406 MySQL \u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u3002\u5982\u679c\u60a8\u9700\u8981\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u904b\u884c\u60a8\u7684 MySQL \u6578\u64da\u5eab\uff0c\u8acb\u8003\u616e\u4f7f\u7528\u6211\u5011\u7684\u670d\u52d9\uff0c\u63d0\u4f9b\u7a69\u5b9a\u548c\u5b89\u5168\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u4f86\u652f\u6301\u60a8\u7684\u696d\u52d9\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u67e5\u770b MySQL \u4e8c\u9032\u5236\u65e5\u8a8c\uff0c\u638c\u63e1\u6578\u64da\u6062\u5fa9\u548c\u8907\u88fd\u7684\u95dc\u9375\u6b65\u9a5f\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-152473","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=152473"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152473\/revisions"}],"predecessor-version":[{"id":152474,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152473\/revisions\/152474"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=152473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=152473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=152473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}