{"id":172587,"date":"2024-11-07T14:22:21","date_gmt":"2024-11-07T06:22:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/172587\/"},"modified":"2024-11-07T14:22:22","modified_gmt":"2024-11-07T06:22:22","slug":"%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8bmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e6%97%a5%e8%aa%8c-%e6%9f%a5%e7%9c%8bmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e6%97%a5%e8%aa%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/172587\/","title":{"rendered":"\u5982\u4f55\u67e5\u770bmysql\u6578\u64da\u5eab\u65e5\u8a8c (\u67e5\u770bmysql\u6578\u64da\u5eab\u65e5\u8a8c)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8bmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e6%97%a5%e8%aa%8c-EbCegzlrLJ\">\u5982\u4f55\u67e5\u770bMySQL\u6578\u64da\u5eab\u65e5\u8a8c<\/h1>\n<p>MySQL\u6578\u64da\u5eab\u65e5\u8a8c\u662f\u7ba1\u7406\u548c\u7dad\u8b77\u6578\u64da\u5eab\u7684\u91cd\u8981\u5de5\u5177\u3002\u901a\u904e\u67e5\u770b\u65e5\u8a8c\uff0c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u53ef\u4ee5\u8ffd\u8e64\u6578\u64da\u5eab\u7684\u6d3b\u52d5\u3001\u8b58\u5225\u554f\u984c\u4ee5\u53ca\u9032\u884c\u6027\u80fd\u8abf\u512a\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u67e5\u770bMySQL\u6578\u64da\u5eab\u65e5\u8a8c\uff0c\u5305\u62ec\u932f\u8aa4\u65e5\u8a8c\u3001\u67e5\u8a62\u65e5\u8a8c\u548c\u4e8c\u9032\u5236\u65e5\u8a8c\u7684\u67e5\u770b\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"1-mysql%e6%97%a5%e8%aa%8c%e7%9a%84%e9%a1%9e%e5%9e%8b-EbCegzlrLJ\">1. MySQL\u65e5\u8a8c\u7684\u985e\u578b<\/h2>\n<p>MySQL\u63d0\u4f9b\u4e86\u5e7e\u7a2e\u4e0d\u540c\u985e\u578b\u7684\u65e5\u8a8c\uff0c\u6bcf\u7a2e\u65e5\u8a8c\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\uff1a<\/p>\n<ul>\n<li><strong>\u932f\u8aa4\u65e5\u8a8c\uff1a<\/strong>\u8a18\u9304MySQL\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\u6240\u6709\u57f7\u884c\u7684SQL\u67e5\u8a62\uff0c\u5c0d\u65bc\u6027\u80fd\u5206\u6790\u548c\u6545\u969c\u6392\u9664\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li><strong>\u4e8c\u9032\u5236\u65e5\u8a8c\uff1a<\/strong>\u8a18\u9304\u6240\u6709\u66f4\u6539\u6578\u64da\u7684\u64cd\u4f5c\uff0c\u4e3b\u8981\u7528\u65bc\u6578\u64da\u6062\u5fa9\u548c\u8907\u88fd\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e6%9f%a5%e7%9c%8b%e9%8c%af%e8%aa%a4%e6%97%a5%e8%aa%8c-EbCegzlrLJ\">2. \u67e5\u770b\u932f\u8aa4\u65e5\u8a8c<\/h2>\n<p>\u932f\u8aa4\u65e5\u8a8c\u901a\u5e38\u4f4d\u65bcMySQL\u6578\u64da\u76ee\u9304\u4e2d\uff0c\u6587\u4ef6\u540d\u901a\u5e38\u70ba <code>hostname.err<\/code>\u3002\u8981\u67e5\u770b\u932f\u8aa4\u65e5\u8a8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>cat \/var\/log\/mysql\/error.log<\/code><\/pre>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fWindows\u7cfb\u7d71\uff0c\u5247\u53ef\u4ee5\u5728MySQL\u5b89\u88dd\u76ee\u9304\u4e0b\u7684 <code>data<\/code> \u6587\u4ef6\u593e\u4e2d\u627e\u5230\u932f\u8aa4\u65e5\u8a8c\u3002<\/p>\n<h3 id=\"2-1-%e4%bd%bf%e7%94%a8mysql%e5%91%bd%e4%bb%a4%e6%9f%a5%e7%9c%8b%e9%8c%af%e8%aa%a4%e6%97%a5%e8%aa%8c-EbCegzlrLJ\">2.1 \u4f7f\u7528MySQL\u547d\u4ee4\u67e5\u770b\u932f\u8aa4\u65e5\u8a8c<\/h3>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u901a\u904eMySQL\u547d\u4ee4\u884c\u5de5\u5177\u67e5\u770b\u932f\u8aa4\u65e5\u8a8c\u3002\u9996\u5148\uff0c\u767b\u9304\u5230MySQL\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>\u7136\u5f8c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u932f\u8aa4\u65e5\u8a8c\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'log_error';<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u932f\u8aa4\u65e5\u8a8c\u7684\u8def\u5f91\uff0c\u60a8\u53ef\u4ee5\u6839\u64da\u8a72\u8def\u5f91\u627e\u5230\u65e5\u8a8c\u6587\u4ef6\u3002<\/p>\n<h2 id=\"3-%e6%9f%a5%e7%9c%8b%e6%9f%a5%e8%a9%a2%e6%97%a5%e8%aa%8c-EbCegzlrLJ\">3. \u67e5\u770b\u67e5\u8a62\u65e5\u8a8c<\/h2>\n<p>\u67e5\u8a62\u65e5\u8a8c\u7684\u67e5\u770b\u65b9\u6cd5\u8207\u932f\u8aa4\u65e5\u8a8c\u985e\u4f3c\u3002\u9996\u5148\uff0c\u78ba\u4fdd\u67e5\u8a62\u65e5\u8a8c\u5df2\u555f\u7528\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'general_log';<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de\u503c\u70ba <code>ON<\/code>\uff0c\u5247\u67e5\u8a62\u65e5\u8a8c\u5df2\u555f\u7528\u3002\u67e5\u8a62\u65e5\u8a8c\u7684\u6587\u4ef6\u540d\u901a\u5e38\u70ba <code>mysql.log<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\uff1a<\/p>\n<pre><code>cat \/var\/log\/mysql\/mysql.log<\/code><\/pre>\n<h3 id=\"3-1-%e4%bd%bf%e7%94%a8mysql%e5%91%bd%e4%bb%a4%e6%9f%a5%e7%9c%8b%e6%9f%a5%e8%a9%a2%e6%97%a5%e8%aa%8c-EbCegzlrLJ\">3.1 \u4f7f\u7528MySQL\u547d\u4ee4\u67e5\u770b\u67e5\u8a62\u65e5\u8a8c<\/h3>\n<p>\u540c\u6a23\uff0c\u60a8\u53ef\u4ee5\u901a\u904eMySQL\u547d\u4ee4\u884c\u5de5\u5177\u67e5\u770b\u67e5\u8a62\u65e5\u8a8c\u3002\u767b\u9304\u5230MySQL\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'general_log_file';<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u67e5\u8a62\u65e5\u8a8c\u7684\u8def\u5f91\uff0c\u60a8\u53ef\u4ee5\u6839\u64da\u8a72\u8def\u5f91\u627e\u5230\u65e5\u8a8c\u6587\u4ef6\u3002<\/p>\n<h2 id=\"4-%e6%9f%a5%e7%9c%8b%e4%ba%8c%e9%80%b2%e5%88%b6%e6%97%a5%e8%aa%8c-EbCegzlrLJ\">4. \u67e5\u770b\u4e8c\u9032\u5236\u65e5\u8a8c<\/h2>\n<p>\u4e8c\u9032\u5236\u65e5\u8a8c\u4e3b\u8981\u7528\u65bc\u6578\u64da\u6062\u5fa9\u548c\u8907\u88fd\u3002\u8981\u67e5\u770b\u4e8c\u9032\u5236\u65e5\u8a8c\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fdd\u4e8c\u9032\u5236\u65e5\u8a8c\u5df2\u555f\u7528\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'log_bin';<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de\u503c\u70ba <code>ON<\/code>\uff0c\u5247\u4e8c\u9032\u5236\u65e5\u8a8c\u5df2\u555f\u7528\u3002\u8981\u67e5\u770b\u4e8c\u9032\u5236\u65e5\u8a8c\u7684\u6587\u4ef6\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>SHOW BINARY LOGS;<\/code><\/pre>\n<p>\u8981\u67e5\u770b\u7279\u5b9a\u7684\u4e8c\u9032\u5236\u65e5\u8a8c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>mysqlbinlog<\/code> \u5de5\u5177\uff1a<\/p>\n<pre><code>mysqlbinlog \/var\/log\/mysql\/mysql-bin.000001<\/code><\/pre>\n<h2 id=\"5-%e7%b8%bd%e7%b5%90-EbCegzlrLJ\">5. \u7e3d\u7d50<\/h2>\n<p>\u67e5\u770bMySQL\u6578\u64da\u5eab\u65e5\u8a8c\u662f\u7dad\u8b77\u6578\u64da\u5eab\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u901a\u904e\u5b9a\u671f\u6aa2\u67e5\u932f\u8aa4\u65e5\u8a8c\u3001\u67e5\u8a62\u65e5\u8a8c\u548c\u4e8c\u9032\u5236\u65e5\u8a8c\uff0c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u53ef\u4ee5\u53ca\u6642\u767c\u73fe\u554f\u984c\u4e26\u9032\u884c\u8abf\u6574\u3002\u4e86\u89e3\u5982\u4f55\u67e5\u770b\u9019\u4e9b\u65e5\u8a8c\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u7a69\u5b9a\u6027\u548c\u6027\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u7528\u6236\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u6578\u64da\u5eab\u7ba1\u7406\u9084\u662f\u7db2\u7ad9\u6258\u7ba1\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u67e5\u770bMySQL\u6578\u64da\u5eab\u65e5\u8a8c\uff0c\u638c\u63e1\u65e5\u8a8c\u6587\u4ef6\u7684\u4f4d\u7f6e\u3001\u683c\u5f0f\u53ca\u4f7f\u7528\u547d\u4ee4\u9032\u884c\u67e5\u8a62\uff0c\u63d0\u5347\u6578\u64da\u5eab\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-172587","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/172587","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=172587"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/172587\/revisions"}],"predecessor-version":[{"id":172588,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/172587\/revisions\/172588"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=172587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=172587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=172587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}