{"id":5252,"date":"2024-11-14T11:06:28","date_gmt":"2024-11-14T03:06:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5252\/"},"modified":"2024-11-14T11:06:28","modified_gmt":"2024-11-14T03:06:28","slug":"mysql-log%e6%80%8e%e4%b9%88%e5%bc%80%e5%90%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5252\/","title":{"rendered":"mysql\u00a0log\u600e\u4e48\u5f00\u542f"},"content":{"rendered":"<blockquote><p>\n  \u901a\u8fc7\u4fee\u6539 mysql \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684 [mysqld] \u90e8\u5206\u5e76\u6dfb\u52a0\u6307\u5b9a\u65e5\u5fd7\u540d\u79f0\u548c\u8981\u8bb0\u5f55\u6570\u636e\u5e93\u7684\u914d\u7f6e\uff0c\u7136\u540e\u91cd\u542f mysql\uff0c\u5373\u53ef\u5f00\u542f mysql \u65e5\u5fd7\u3002\u9a8c\u8bc1\u65e5\u5fd7\u662f\u5426\u5df2\u5f00\u542f\u7684\u65b9\u6cd5\u662f\u8fde\u63a5\u5230 mysql \u5e76\u8fd0\u884c show binary logs \u67e5\u8be2\u3002\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 mysqlbinlog \u547d\u4ee4\u6765\u67e5\u770b\u65e5\u5fd7\u7684\u5185\u5bb9\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052617364182657.jpg\" class=\"aligncenter\" title=\"mysql\u00a0log\u600e\u4e48\u5f00\u542f\u63d2\u56fe\" alt=\"mysql\u00a0log\u600e\u4e48\u5f00\u542f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5f00\u542f MySQL \u65e5\u5fd7<\/strong><\/p>\n<p>MySQL\u65e5\u5fd7\u662f\u8bb0\u5f55\u6570\u636e\u5e93\u64cd\u4f5c\u548c\u4e8b\u4ef6\u7684\u91cd\u8981\u5de5\u5177\u3002\u5f00\u542f\u65e5\u5fd7\u53ef\u4ee5\u5e2e\u52a9\u8bca\u65ad\u9519\u8bef\u3001\u8ddf\u8e2a\u7528\u6237\u6d3b\u52a8\u5e76\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002\u4ee5\u4e0b\u662f\u5f00\u542f MySQL \u65e5\u5fd7\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u914d\u7f6e MySQL \u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u7f16\u8f91 MySQL \u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\/etc\/\/my.cnf\u6216\/usr\/local\/mysql\/etc\/my.cnf\uff09\uff0c\u627e\u5230 [mysqld] \u90e8\u5206\uff0c\u7136\u540e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>log-bin=mysql-bin\nbinlog-do-db=database_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>log-bin \u6307\u5b9a\u4e8c\u8fdb\u5236\u65e5\u5fd7\u7684\u540d\u79f0\u3002<\/li>\n<li>binlog-do-db \u6307\u5b9a\u8981\u8bb0\u5f55\u5176\u64cd\u4f5c\u7684\u6570\u636e\u5e93\u3002<\/li>\n<\/ul>\n<p><strong>2. \u91cd\u542f MySQL<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u542f MySQL\uff1a<\/p>\n<pre>sudo service mysql restart<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6216<\/p>\n<pre>sudo systemctl restart mysql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u9a8c\u8bc1\u65e5\u5fd7\u662f\u5426\u5df2\u5f00\u542f<\/strong><\/p>\n<p>\u8fde\u63a5\u5230 MySQL \u5e76\u8fd0\u884c\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SHOW BINARY LOGS;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u5e94\u5305\u542b\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>Log_name             Pos   Flags   Info\n--------------------- ----- ----- -----------------------------------\nmysql-bin.000001     4      31   mysql-bin rotated to mysql-bin.000001<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u8868\u793a\u4e8c\u8fdb\u5236\u65e5\u5fd7\u5df2\u542f\u7528\u3002<\/p>\n<p><strong>4. \u67e5\u770b\u65e5\u5fd7<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u4e8c\u8fdb\u5236\u65e5\u5fd7\u7684\u5185\u5bb9\uff1a<\/p>\n<pre>mysqlbinlog mysql-bin.000001<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u6253\u5370\u65e5\u5fd7\u4e2d\u7684\u6240\u6709\u6761\u76ee\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f&nbsp;log\u600e\u4e48\u5f00\u542f\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>\u901a\u8fc7\u4fee\u6539 mysql \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684 [mysqld] \u90e8\u5206\u5e76\u6dfb\u52a0\u6307\u5b9a\u65e5\u5fd7\u540d\u79f0\u548c\u8981\u8bb0\u5f55\u6570\u636e\u5e93\u7684\u914d\u7f6e\uff0c\u7136\u540e\u91cd\u542f mysql\uff0c\u5373\u53ef\u5f00\u542f mysql \u65e5\u5fd7\u3002\u9a8c\u8bc1\u65e5\u5fd7\u662f\u5426\u5df2\u5f00\u542f\u7684\u65b9\u6cd5\u662f\u8fde\u63a5\u5230 mysql \u5e76\u8fd0\u884c show binary logs \u67e5\u8be2\u3002\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 mysqlbinlog \u547d\u4ee4\u6765\u67e5\u770b\u65e5\u5fd7\u7684\u5185\u5bb9\u3002 \u5982\u4f55\u5f00\u542f MySQL \u65e5\u5fd7 MySQL\u65e5\u5fd7\u662f\u8bb0\u5f55\u6570\u636e\u5e93\u64cd\u4f5c\u548c\u4e8b\u4ef6\u7684\u91cd\u8981\u5de5\u5177\u3002\u5f00\u542f\u65e5\u5fd7\u53ef\u4ee5\u5e2e\u52a9\u8bca\u65ad\u9519\u8bef\u3001\u8ddf\u8e2a\u7528\u6237\u6d3b\u52a8\u5e76\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002\u4ee5\u4e0b\u662f\u5f00\u542f MySQL \u65e5\u5fd7\u7684\u6b65\u9aa4\uff1a 1. \u914d\u7f6e MySQL \u914d\u7f6e\u6587\u4ef6 \u7f16\u8f91 MySQL \u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\/etc\/\/my.cnf\u6216\/usr\/local\/mysql\/etc\/my.cnf\uff09\uff0c\u627e\u5230 [mysqld] \u90e8\u5206\uff0c\u7136\u540e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a log-bin=mysql-bin binlog-do-db=database_name \u767b\u5f55\u540e\u590d\u5236 log-bin \u6307\u5b9a\u4e8c\u8fdb\u5236\u65e5\u5fd7\u7684\u540d\u79f0\u3002 binlog-do-db \u6307\u5b9a\u8981\u8bb0\u5f55\u5176\u64cd\u4f5c\u7684\u6570\u636e\u5e93\u3002 2. \u91cd\u542f MySQL \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u542f MySQL\uff1a sudo service mysql restart \u767b\u5f55\u540e\u590d\u5236 \u6216 sudo systemctl restart mysql \u767b\u5f55\u540e\u590d\u5236 3. [&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-5252","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5252","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=5252"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5252\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}