{"id":5279,"date":"2024-11-14T08:58:37","date_gmt":"2024-11-14T00:58:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5279\/"},"modified":"2024-11-14T08:58:37","modified_gmt":"2024-11-14T00:58:37","slug":"%e6%80%8e%e4%b9%88%e5%90%af%e5%8a%a8mysql%e6%97%a5%e5%bf%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5279\/","title":{"rendered":"\u600e\u4e48\u542f\u52a8mysql\u65e5\u5fd7"},"content":{"rendered":"<blockquote><p>\n  \u542f\u52a8 mysql \u65e5\u5fd7\u5206\u4e03\u6b65\uff1a\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\u5e76\u6dfb\u52a0 log-bin \u548c binlog-format \u8bed\u53e5\u3002\u91cd\u542f mysql\u3002\u4f7f\u7528 show binary logs \u68c0\u67e5\u4e8c\u8fdb\u5236\u65e5\u5fd7\u662f\u5426\u542f\u7528\u3002\u6dfb\u52a0 log-error \u8bed\u53e5\u542f\u7528\u9519\u8bef\u65e5\u5fd7\u3002\u518d\u6b21\u91cd\u542f mysql\u3002\u4f7f\u7528 mysqlbinlog \u67e5\u770b\u4e8c\u8fdb\u5236\u65e5\u5fd7\u3002\u4f7f\u7528 tail -f \u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052618184024395.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u542f\u52a8mysql\u65e5\u5fd7\u63d2\u56fe\" alt=\"\u600e\u4e48\u542f\u52a8mysql\u65e5\u5fd7\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u542f\u52a8 MySQL \u65e5\u5fd7\uff1f<\/strong><\/p>\n<p>\u542f\u52a8 MySQL \u65e5\u5fd7\u662f\u6536\u96c6\u6709\u5173\u6570\u636e\u5e93\u6d3b\u52a8\u548c\u9519\u8bef\u7684\u4fe1\u606f\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u8fd9\u5bf9\u4e8e\u6545\u969c\u6392\u9664\u3001\u6027\u80fd\u4f18\u5316\u548c\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u542f\u52a8 MySQL \u65e5\u5fd7\u7684\u5206\u6b65\u6307\u5357\uff1a<\/p>\n<p><strong>1. \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u6253\u5f00 MySQL \u914d\u7f6e\u6587\u4ef6 (my.cnf)\u3002\u5728\u5927\u591a\u6570\u7cfb\u7edf\u4e0a\uff0c\u8be5\u6587\u4ef6\u4f4d\u4e8e \/etc\/\/my.cnf \u6216 \/etc\/my.cnf\u3002<\/p>\n<p><strong>2. \u6dfb\u52a0\u65e5\u5fd7\u8bed\u53e5<\/strong><\/p>\n<p>\u5728 [mysqld] \u90e8\u5206\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>log-bin=mysql-bin\nbinlog-format=ROW<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>log-bin=mysql-bin\uff1a<\/strong>\u6307\u5b9a\u5c06\u4e8c\u8fdb\u5236\u65e5\u5fd7\u4fdd\u5b58\u5230 mysql-bin \u6587\u4ef6\u3002<\/li>\n<li> <strong>binlog-format=ROW\uff1a<\/strong>\u4f7f\u7528\u884c\u7ea7\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\uff0c\u8fd9\u662f\u6700\u8be6\u7ec6\u7684\u65e5\u5fd7\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<p><strong>3. \u91cd\u542f MySQL<\/strong><\/p>\n<p>\u4fdd\u5b58\u914d\u7f6e\u6587\u4ef6\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u542f MySQL\uff1a<\/p>\n<pre>service mysql restart<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u9a8c\u8bc1\u65e5\u5fd7<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u4e8c\u8fdb\u5236\u65e5\u5fd7\u662f\u5426\u5df2\u542f\u7528\uff1a<\/p>\n<pre>mysql -e \"SHOW BINARY LOGS\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u542f\u7528\u9519\u8bef\u65e5\u5fd7<\/strong><\/p>\n<p>\u8981\u542f\u7528\u9519\u8bef\u65e5\u5fd7\uff0c\u8bf7\u5728 [mysqld] \u90e8\u5206\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>log-error=\/var\/log\/mysql\/error.log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>log-error=\/var\/log\/mysql\/error.log\uff1a<\/strong>\u6307\u5b9a\u9519\u8bef\u65e5\u5fd7\u7684\u6587\u4ef6\u8def\u5f84\u3002<\/li>\n<\/ul>\n<p><strong>6. \u91cd\u542f MySQL<\/strong><\/p>\n<p>\u518d\u6b21\u91cd\u542f MySQL \u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/p>\n<p><strong>7. \u67e5\u770b\u65e5\u5fd7<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff1a<\/p>\n<pre>mysqlbinlog mysql-bin.000001<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u9519\u8bef\u65e5\u5fd7\uff1a<\/p>\n<pre>tail -f \/var\/log\/mysql\/error.log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u542f\u52a8\u65e5\u5fd7\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\u52a8 mysql \u65e5\u5fd7\u5206\u4e03\u6b65\uff1a\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\u5e76\u6dfb\u52a0 log-bin \u548c binlog-format \u8bed\u53e5\u3002\u91cd\u542f mysql\u3002\u4f7f\u7528 show binary logs \u68c0\u67e5\u4e8c\u8fdb\u5236\u65e5\u5fd7\u662f\u5426\u542f\u7528\u3002\u6dfb\u52a0 log-error \u8bed\u53e5\u542f\u7528\u9519\u8bef\u65e5\u5fd7\u3002\u518d\u6b21\u91cd\u542f mysql\u3002\u4f7f\u7528 mysqlbinlog \u67e5\u770b\u4e8c\u8fdb\u5236\u65e5\u5fd7\u3002\u4f7f\u7528 tail -f \u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u3002 \u5982\u4f55\u542f\u52a8 MySQL \u65e5\u5fd7\uff1f \u542f\u52a8 MySQL \u65e5\u5fd7\u662f\u6536\u96c6\u6709\u5173\u6570\u636e\u5e93\u6d3b\u52a8\u548c\u9519\u8bef\u7684\u4fe1\u606f\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u8fd9\u5bf9\u4e8e\u6545\u969c\u6392\u9664\u3001\u6027\u80fd\u4f18\u5316\u548c\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u542f\u52a8 MySQL \u65e5\u5fd7\u7684\u5206\u6b65\u6307\u5357\uff1a 1. \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6 \u6253\u5f00 MySQL \u914d\u7f6e\u6587\u4ef6 (my.cnf)\u3002\u5728\u5927\u591a\u6570\u7cfb\u7edf\u4e0a\uff0c\u8be5\u6587\u4ef6\u4f4d\u4e8e \/etc\/\/my.cnf \u6216 \/etc\/my.cnf\u3002 2. \u6dfb\u52a0\u65e5\u5fd7\u8bed\u53e5 \u5728 [mysqld] \u90e8\u5206\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a log-bin=mysql-bin binlog-format=ROW \u767b\u5f55\u540e\u590d\u5236 log-bin=mysql-bin\uff1a\u6307\u5b9a\u5c06\u4e8c\u8fdb\u5236\u65e5\u5fd7\u4fdd\u5b58\u5230 mysql-bin \u6587\u4ef6\u3002 binlog-format=ROW\uff1a\u4f7f\u7528\u884c\u7ea7\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\uff0c\u8fd9\u662f\u6700\u8be6\u7ec6\u7684\u65e5\u5fd7\u683c\u5f0f\u3002 3. \u91cd\u542f MySQL \u4fdd\u5b58\u914d\u7f6e\u6587\u4ef6\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u542f MySQL\uff1a service [&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-5279","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5279","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=5279"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5279\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}