{"id":173315,"date":"2024-11-07T17:00:20","date_gmt":"2024-11-07T09:00:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/173315\/"},"modified":"2024-11-07T17:00:21","modified_gmt":"2024-11-07T09:00:21","slug":"%e5%a6%82%e4%bd%95%e5%b0%8dmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e6%97%a5%e8%aa%8c%e6%96%87%e4%bb%b6%e9%80%b2%e8%a1%8c%e7%b6%ad%e8%ad%b7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/173315\/","title":{"rendered":"\u5982\u4f55\u5c0dMySQL\u6578\u64da\u5eab\u65e5\u8a8c\u6587\u4ef6\u9032\u884c\u7dad\u8b77"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%b0%8dmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e6%97%a5%e8%aa%8c%e6%96%87%e4%bb%b6%e9%80%b2%e8%a1%8c%e7%b6%ad%e8%ad%b7-PlMYighwxx\">\u5982\u4f55\u5c0dMySQL\u6578\u64da\u5eab\u65e5\u8a8c\u6587\u4ef6\u9032\u884c\u7dad\u8b77<\/h1>\n<p>MySQL\u6578\u64da\u5eab\u5728\u65e5\u5e38\u904b\u884c\u4e2d\u6703\u751f\u6210\u5927\u91cf\u7684\u65e5\u8a8c\u6587\u4ef6\uff0c\u9019\u4e9b\u65e5\u8a8c\u6587\u4ef6\u5c0d\u65bc\u6578\u64da\u5eab\u7684\u6027\u80fd\u76e3\u63a7\u3001\u6545\u969c\u6392\u67e5\u4ee5\u53ca\u6578\u64da\u6062\u5fa9\u7b49\u65b9\u9762\u90fd\u8d77\u8457\u81f3\u95dc\u91cd\u8981\u7684\u4f5c\u7528\u3002\u7136\u800c\uff0c\u96a8\u8457\u6642\u9593\u7684\u63a8\u79fb\uff0c\u9019\u4e9b\u65e5\u8a8c\u6587\u4ef6\u53ef\u80fd\u6703\u4f54\u7528\u5927\u91cf\u7684\u78c1\u789f\u7a7a\u9593\uff0c\u5f71\u97ff\u6578\u64da\u5eab\u7684\u6027\u80fd\u3002\u56e0\u6b64\uff0c\u5c0dMySQL\u6578\u64da\u5eab\u65e5\u8a8c\u6587\u4ef6\u9032\u884c\u5b9a\u671f\u7dad\u8b77\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u6709\u6548\u5730\u7dad\u8b77MySQL\u6578\u64da\u5eab\u7684\u65e5\u8a8c\u6587\u4ef6\u3002<\/p>\n<h2 id=\"1-%e7%90%86%e8%a7%a3mysql%e6%97%a5%e8%aa%8c%e6%96%87%e4%bb%b6%e7%9a%84%e9%a1%9e%e5%9e%8b-PlMYighwxx\">1. \u7406\u89e3MySQL\u65e5\u8a8c\u6587\u4ef6\u7684\u985e\u578b<\/h2>\n<p>\u5728\u958b\u59cb\u7dad\u8b77\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u4e86\u89e3MySQL\u751f\u6210\u7684\u4e0d\u540c\u985e\u578b\u7684\u65e5\u8a8c\u6587\u4ef6\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u932f\u8aa4\u65e5\u8a8c\uff1a<\/strong>\u8a18\u9304\u4e86MySQL\u4f3a\u670d\u5668\u555f\u52d5\u3001\u904b\u884c\u548c\u95dc\u9589\u904e\u7a0b\u4e2d\u7684\u932f\u8aa4\u4fe1\u606f\u3002<\/li>\n<li><strong>\u67e5\u8a62\u65e5\u8a8c\uff1a<\/strong>\u8a18\u9304\u4e86\u6240\u6709\u57f7\u884c\u7684SQL\u67e5\u8a62\uff0c\u5c0d\u65bc\u6027\u80fd\u5206\u6790\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li><strong>\u4e8c\u9032\u5236\u65e5\u8a8c\uff1a<\/strong>\u8a18\u9304\u4e86\u6240\u6709\u66f4\u6539\u6578\u64da\u7684\u64cd\u4f5c\uff0c\u4e3b\u8981\u7528\u65bc\u6578\u64da\u6062\u5fa9\u548c\u8907\u88fd\u3002<\/li>\n<li><strong>\u6162\u67e5\u8a62\u65e5\u8a8c\uff1a<\/strong>\u8a18\u9304\u4e86\u57f7\u884c\u6642\u9593\u8d85\u904e\u6307\u5b9a\u95be\u503c\u7684\u67e5\u8a62\uff0c\u5e6b\u52a9\u8b58\u5225\u6027\u80fd\u74f6\u9838\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e5%ae%9a%e6%9c%9f%e6%b8%85%e7%90%86%e6%97%a5%e8%aa%8c%e6%96%87%e4%bb%b6-PlMYighwxx\">2. \u5b9a\u671f\u6e05\u7406\u65e5\u8a8c\u6587\u4ef6<\/h2>\n<p>\u96a8\u8457\u6642\u9593\u7684\u63a8\u79fb\uff0c\u65e5\u8a8c\u6587\u4ef6\u6703\u4e0d\u65b7\u589e\u9577\uff0c\u56e0\u6b64\u5b9a\u671f\u6e05\u7406\u662f\u5fc5\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u4f86\u6e05\u7406\u65e5\u8a8c\u6587\u4ef6\uff1a<\/p>\n<h3 id=\"2-1-%e6%b8%85%e7%90%86%e9%8c%af%e8%aa%a4%e6%97%a5%e8%aa%8c-PlMYighwxx\">2.1 \u6e05\u7406\u932f\u8aa4\u65e5\u8a8c<\/h3>\n<p>\u932f\u8aa4\u65e5\u8a8c\u901a\u5e38\u4e0d\u9700\u8981\u9577\u671f\u4fdd\u5b58\uff0c\u53ef\u4ee5\u5b9a\u671f\u522a\u9664\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6e05\u7406\u932f\u8aa4\u65e5\u8a8c\uff1a<\/p>\n<pre><code>mysqladmin -u root -p flush-error-log<\/code><\/pre>\n<h3 id=\"2-2-%e6%b8%85%e7%90%86%e6%9f%a5%e8%a9%a2%e6%97%a5%e8%aa%8c-PlMYighwxx\">2.2 \u6e05\u7406\u67e5\u8a62\u65e5\u8a8c<\/h3>\n<p>\u67e5\u8a62\u65e5\u8a8c\u53ef\u4ee5\u901a\u904e\u8a2d\u7f6eMySQL\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u53c3\u6578\u4f86\u9650\u5236\u5176\u5927\u5c0f\uff0c\u4e26\u5b9a\u671f\u6e05\u7406\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728my.cnf\u4e2d\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>[mysqld]\ngeneral_log = 1\ngeneral_log_file = \/var\/log\/mysql\/mysql.log\nexpire_logs_days = 7<\/code><\/pre>\n<p>\u9019\u6a23\u8a2d\u7f6e\u5f8c\uff0c\u67e5\u8a62\u65e5\u8a8c\u5c07\u57287\u5929\u5f8c\u81ea\u52d5\u522a\u9664\u3002<\/p>\n<h3 id=\"2-3-%e6%b8%85%e7%90%86%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c-PlMYighwxx\">2.3 \u6e05\u7406\u4e8c\u9032\u5236\u65e5\u8a8c<\/h3>\n<p>\u4e8c\u9032\u5236\u65e5\u8a8c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6e05\u7406\uff1a<\/p>\n<pre><code>PURGE BINARY LOGS TO 'mysql-bin.000010';<\/code><\/pre>\n<p>\u9019\u5c07\u522a\u9664\u6240\u6709\u5728\u6307\u5b9a\u4e8c\u9032\u5236\u65e5\u8a8c\u4e4b\u524d\u7684\u65e5\u8a8c\u6587\u4ef6\u3002<\/p>\n<h3 id=\"2-4-%e6%b8%85%e7%90%86%e6%85%a2%e6%9f%a5%e8%a9%a2%e6%97%a5%e8%aa%8c-PlMYighwxx\">2.4 \u6e05\u7406\u6162\u67e5\u8a62\u65e5\u8a8c<\/h3>\n<p>\u6162\u67e5\u8a62\u65e5\u8a8c\u7684\u6e05\u7406\u65b9\u6cd5\u8207\u67e5\u8a62\u65e5\u8a8c\u985e\u4f3c\uff0c\u53ef\u4ee5\u8a2d\u7f6e\u904e\u671f\u6642\u9593\u4f86\u81ea\u52d5\u6e05\u7406\u3002<\/p>\n<h2 id=\"3-%e7%9b%a3%e6%8e%a7%e6%97%a5%e8%aa%8c%e6%96%87%e4%bb%b6%e7%9a%84%e5%a4%a7%e5%b0%8f-PlMYighwxx\">3. \u76e3\u63a7\u65e5\u8a8c\u6587\u4ef6\u7684\u5927\u5c0f<\/h2>\n<p>\u70ba\u4e86\u907f\u514d\u65e5\u8a8c\u6587\u4ef6\u4f54\u7528\u904e\u591a\u7684\u78c1\u789f\u7a7a\u9593\uff0c\u53ef\u4ee5\u4f7f\u7528\u76e3\u63a7\u5de5\u5177\u4f86\u5b9a\u671f\u6aa2\u67e5\u65e5\u8a8c\u6587\u4ef6\u7684\u5927\u5c0f\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u67e5\u770b\u65e5\u8a8c\u6587\u4ef6\u7684\u5927\u5c0f\uff1a<\/p>\n<pre><code>du -sh \/var\/log\/mysql\/*<\/code><\/pre>\n<p>\u6839\u64da\u6aa2\u67e5\u7d50\u679c\uff0c\u6c7a\u5b9a\u662f\u5426\u9700\u8981\u9032\u884c\u6e05\u7406\u3002<\/p>\n<h2 id=\"4-%e8%a8%ad%e7%bd%ae%e6%97%a5%e8%aa%8c%e8%bc%aa%e6%9b%bf-PlMYighwxx\">4. \u8a2d\u7f6e\u65e5\u8a8c\u8f2a\u66ff<\/h2>\n<p>\u70ba\u4e86\u66f4\u597d\u5730\u7ba1\u7406\u65e5\u8a8c\u6587\u4ef6\uff0c\u53ef\u4ee5\u8003\u616e\u8a2d\u7f6e\u65e5\u8a8c\u8f2a\u66ff\u3002\u9019\u6a23\u53ef\u4ee5\u5728\u9054\u5230\u4e00\u5b9a\u5927\u5c0f\u6216\u6642\u9593\u5f8c\u81ea\u52d5\u5275\u5efa\u65b0\u7684\u65e5\u8a8c\u6587\u4ef6\uff0c\u4e26\u522a\u9664\u820a\u7684\u65e5\u8a8c\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528logrotate\u5de5\u5177\u4f86\u5be6\u73fe\u9019\u4e00\u529f\u80fd\u3002<\/p>\n<h2 id=\"5-%e5%ae%9a%e6%9c%9f%e5%82%99%e4%bb%bd%e6%97%a5%e8%aa%8c%e6%96%87%e4%bb%b6-PlMYighwxx\">5. \u5b9a\u671f\u5099\u4efd\u65e5\u8a8c\u6587\u4ef6<\/h2>\n<p>\u5728\u9032\u884c\u65e5\u8a8c\u6e05\u7406\u4e4b\u524d\uff0c\u5efa\u8b70\u5b9a\u671f\u5099\u4efd\u91cd\u8981\u7684\u65e5\u8a8c\u6587\u4ef6\uff0c\u4ee5\u9632\u6b62\u6578\u64da\u4e1f\u5931\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5099\u4efd\uff1a<\/p>\n<pre><code>cp \/var\/log\/mysql\/mysql.log \/backup\/mysql.log.bak<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-PlMYighwxx\">\u7e3d\u7d50<\/h2>\n<p>\u5c0dMySQL\u6578\u64da\u5eab\u65e5\u8a8c\u6587\u4ef6\u7684\u7dad\u8b77\u662f\u78ba\u4fdd\u6578\u64da\u5eab\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u901a\u904e\u5b9a\u671f\u6e05\u7406\u3001\u76e3\u63a7\u65e5\u8a8c\u5927\u5c0f\u3001\u8a2d\u7f6e\u65e5\u8a8c\u8f2a\u66ff\u4ee5\u53ca\u5099\u4efd\u65e5\u8a8c\u6587\u4ef6\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u65e5\u8a8c\u6587\u4ef6\uff0c\u907f\u514d\u4f54\u7528\u904e\u591a\u7684\u78c1\u789f\u7a7a\u9593\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u5eab\u7ba1\u7406\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u89e3\u6c7a\u65b9\u6848\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u6574\u9ad4\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u6709\u6548\u7dad\u8b77MySQL\u6578\u64da\u5eab\u65e5\u8a8c\u6587\u4ef6\uff0c\u78ba\u4fdd\u6578\u64da\u5b8c\u6574\u6027\u548c\u7cfb\u7d71\u6027\u80fd\uff0c\u907f\u514d\u6f5b\u5728\u7684\u554f\u984c\u548c\u6578\u64da\u640d\u5931\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-173315","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/173315","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=173315"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/173315\/revisions"}],"predecessor-version":[{"id":173316,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/173315\/revisions\/173316"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=173315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=173315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=173315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}