{"id":6520,"date":"2024-11-14T10:04:01","date_gmt":"2024-11-14T02:04:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6520\/"},"modified":"2024-11-14T10:04:01","modified_gmt":"2024-11-14T02:04:01","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%97%a5%e5%bf%97%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6520\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u65e5\u5fd7\u600e\u4e48\u5220\u9664"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5220\u9664 mysql \u6570\u636e\u5e93\u65e5\u5fd7\uff0c\u6709\u56db\u79cd\u65b9\u6cd5\uff1a1. \u624b\u52a8\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\uff1b2. \u4f7f\u7528 mysqladmin \u547d\u4ee4\uff1b3. \u4f7f\u7528 mysql \u547d\u4ee4\uff1b4. \u7f16\u8f91 mysql \u914d\u7f6e\u6587\u4ef6\u3002\u5728\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u5df2\u5907\u4efd\u5b83\u4eec\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080519431029471.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u65e5\u5fd7\u600e\u4e48\u5220\u9664\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u65e5\u5fd7\u600e\u4e48\u5220\u9664\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u65e5\u5fd7<\/strong><\/p>\n<p>\u8981\u5220\u9664 MySQL \u6570\u636e\u5e93\u65e5\u5fd7\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u624b\u52a8\u5220\u9664\u65e5\u5fd7\u6587\u4ef6<\/strong><\/p>\n<ul>\n<li>\n<p>\u67e5\u627e\u65e5\u5fd7\u6587\u4ef6\u7684\u4f4d\u7f6e\uff1a<\/p>\n<pre>show variables like \"log_bin%\";<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\u505c\u6b62 MySQL \u670d\u52a1\u3002<\/li>\n<li>\u5bfc\u822a\u5230\u65e5\u5fd7\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u5e76\u5220\u9664\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>2. \u4f7f\u7528 admin \u547d\u4ee4<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff1a<\/p>\n<pre>mysqladmin flush-logs --binary<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u901a\u7528\u67e5\u8be2\u65e5\u5fd7\uff1a<\/p>\n<pre>mysqladmin flush-logs --general<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u6162\u67e5\u8be2\u65e5\u5fd7\uff1a<\/p>\n<pre>mysqladmin flush-logs --slow<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>3. \u4f7f\u7528 MySQL \u547d\u4ee4<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff1a<\/p>\n<pre>RESET MASTER;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u901a\u7528\u67e5\u8be2\u65e5\u5fd7\uff1a<\/p>\n<pre>SET GLOBAL general_log = 0;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u6162\u67e5\u8be2\u65e5\u5fd7\uff1a<\/p>\n<pre>SET GLOBAL slow_query_log = 0;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>4. \u7f16\u8f91 MySQL \u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<ul>\n<li>\u6253\u5f00 MySQL \u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e \/etc\/my.cnf\uff09\u3002<\/li>\n<li>\u6ce8\u91ca\u6389 log_bin\u3001general_log \u548c slow_query_log \u8bbe\u7f6e\u3002<\/li>\n<li>\u91cd\u65b0\u542f\u52a8 MySQL \u670d\u52a1\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u5df2\u5907\u4efd\u5b83\u4eec\uff0c\u4ee5\u9632\u5c06\u6765\u9700\u8981\u8fdb\u884c\u6545\u969c\u6392\u9664\u3002<\/li>\n<li>\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\u4e0d\u4f1a\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\u4e2d\u8bb0\u5f55\u7684\u4e8b\u4ef6\u3002\u8981\u6e05\u9664\u4e8b\u4ef6\u5386\u53f2\u8bb0\u5f55\uff0c\u8bf7\u4f7f\u7528 PURGE BINARY LOGS \u547d\u4ee4\u3002<\/li>\n<li>\u9891\u7e41\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\u4f1a\u5f71\u54cd MySQL \u7684\u6027\u80fd\u3002\u5efa\u8bae\u5b9a\u671f\u65cb\u8f6c\u65e5\u5fd7\u6587\u4ef6\u800c\u4e0d\u662f\u5220\u9664\u5b83\u4eec\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u65e5\u5fd7\u600e\u4e48\u5220\u9664\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>\u8981\u5220\u9664 mysql \u6570\u636e\u5e93\u65e5\u5fd7\uff0c\u6709\u56db\u79cd\u65b9\u6cd5\uff1a1. \u624b\u52a8\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\uff1b2. \u4f7f\u7528 mysqladmin \u547d\u4ee4\uff1b3. \u4f7f\u7528 mysql \u547d\u4ee4\uff1b4. \u7f16\u8f91 mysql \u914d\u7f6e\u6587\u4ef6\u3002\u5728\u5220\u9664\u65e5\u5fd7\u6587\u4ef6\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u5df2\u5907\u4efd\u5b83\u4eec\u3002 \u5982\u4f55\u5220\u9664 MySQL \u6570\u636e\u5e93\u65e5\u5fd7 \u8981\u5220\u9664 MySQL \u6570\u636e\u5e93\u65e5\u5fd7\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a 1. \u624b\u52a8\u5220\u9664\u65e5\u5fd7\u6587\u4ef6 \u67e5\u627e\u65e5\u5fd7\u6587\u4ef6\u7684\u4f4d\u7f6e\uff1a show variables like &#8220;log_bin%&#8221;; \u767b\u5f55\u540e\u590d\u5236 \u505c\u6b62 MySQL \u670d\u52a1\u3002 \u5bfc\u822a\u5230\u65e5\u5fd7\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u5e76\u5220\u9664\u6587\u4ef6\u3002 2. \u4f7f\u7528 admin \u547d\u4ee4 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff1a mysqladmin flush-logs &#8211;binary \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u901a\u7528\u67e5\u8be2\u65e5\u5fd7\uff1a mysqladmin flush-logs &#8211;general \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u6162\u67e5\u8be2\u65e5\u5fd7\uff1a mysqladmin flush-logs &#8211;slow \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528 MySQL \u547d\u4ee4 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff1a [&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-6520","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6520","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=6520"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6520\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}