{"id":474,"date":"2008-01-28T00:00:00","date_gmt":"2008-01-27T16:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=474"},"modified":"2011-07-15T09:44:49","modified_gmt":"2011-07-15T01:44:49","slug":"%e7%94%a8mysqldumpslow%e5%88%86%e6%9e%90mysql%e7%9a%84slow-query-log","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=474","title":{"rendered":"\u7528mysqldumpslow\u5206\u6790mysql\u7684slow query log"},"content":{"rendered":"<p><DIV>mysql\u6709\u4e00\u4e2a\u529f\u80fd\u5c31\u662f\u53ef\u4ee5log\u4e0b\u6765\u8fd0\u884c\u7684\u6bd4\u8f83\u6162\u7684sql\u8bed\u53e5\uff0c\u9ed8\u8ba4\u662f\u6ca1\u6709\u8fd9\u4e2alog\u7684\uff0c\u4e3a\u4e86\u5f00\u542f\u8fd9\u4e2a\u529f\u80fd\uff0c\u8981\u4fee\u6539my.cnf\u6216\u8005\u5728mysql\u542f\u52a8\u7684\u65f6\u5019\u52a0\u5165\u4e00\u4e9b\u53c2\u6570\u3002\u5982\u679c\u5728my.cnf\u91cc\u9762\u4fee\u6539\uff0c\u9700\u589e\u52a0\u5982\u4e0b\u51e0\u884c<\/DIV><br \/>\n<DIV>long_query_time = 1<BR>log-slow-queries = \/var\/youpath\/slow.log<BR>log-queries-not-using-indexes<\/DIV><br \/>\n<DIV>long_query_time \u662f\u6307\u6267\u884c\u8d85\u8fc7\u591a\u4e45\u7684sql\u4f1a\u88ablog\u4e0b\u6765\uff0c\u8fd9\u91cc\u662f1\u79d2\u3002<BR>log-slow-queries \u8bbe\u7f6e\u628a\u65e5\u5fd7\u5199\u5728\u90a3\u91cc\uff0c\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u7cfb\u7edf\u4f1a\u7ed9\u4e00\u4e2a\u7f3a\u7701\u7684\u6587\u4ef6host_name-slow.log\uff0c\u6211\u751f\u6210\u7684log\u5c31\u5728mysql\u7684data\u76ee\u5f55<BR>log-queries-not-using-indexes \u5c31\u662f\u5b57\u9762\u610f\u601d\uff0clog\u4e0b\u6765\u6ca1\u6709\u4f7f\u7528\u7d22\u5f15\u7684query\u3002<\/DIV><br \/>\n<DIV>\u628a\u4e0a\u8ff0\u53c2\u6570\u6253\u5f00\uff0c\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\uff0c\u5c31\u53ef\u4ee5\u5173\u6389\u4e86\uff0c\u7701\u5f97\u5f71\u54cd\u751f\u4ea7\u73af\u5883\u3002<\/DIV><br \/>\n<DIV>\u63a5\u4e0b\u6765\u5c31\u662f\u5206\u6790\u4e86\uff0c\u6211\u8fd9\u91cc\u7684\u6587\u4ef6\u540d\u5b57\u53ebhost-slow.log\u3002<BR>\u5148mysqldumpslow \u2013help\u4ee5\u4e0b\uff0c\u4ffa\u4e3b\u8981\u7528\u7684\u662f<BR>-s ORDER what to sort by (t, at, l, al, r, ar etc), \u2018at\u2019 is default<BR>-t NUM just show the top n queries<BR>-g PATTERN grep: only consider stmts that include this string<\/DIV><br \/>\n<DIV>-s\uff0c\u662forder\u7684\u987a\u5e8f\uff0c\u8bf4\u660e\u5199\u7684\u4e0d\u591f\u8be6\u7ec6\uff0c\u4ffa\u7528\u4e0b\u6765\uff0c\u5305\u62ec\u770b\u4e86\u4ee3\u7801\uff0c\u4e3b\u8981\u6709<BR>c,t,l,r\u548cac,at,al,ar\uff0c\u5206\u522b\u662f\u6309\u7167query\u6b21\u6570\uff0c\u65f6\u95f4\uff0clock\u7684\u65f6\u95f4\u548c\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u6765\u6392\u5e8f\uff0c\u524d\u9762\u52a0\u4e86a\u7684\u65f6\u5012\u53d9<BR>-t\uff0c\u662ftop n\u7684\u610f\u601d\uff0c\u5373\u4e3a\u8fd4\u56de\u524d\u9762\u591a\u5c11\u6761\u7684\u6570\u636e<BR>-g\uff0c\u540e\u8fb9\u53ef\u4ee5\u5199\u4e00\u4e2a\u6b63\u5219\u5339\u914d\u6a21\u5f0f\uff0c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684<\/DIV><br \/>\n<DIV>mysqldumpslow -s c -t 20 host-slow.log<BR>mysqldumpslow -s r -t 20 host-slow.log<\/DIV><br \/>\n<DIV>\u4e0a\u8ff0\u547d\u4ee4\u53ef\u4ee5\u770b\u51fa\u8bbf\u95ee\u6b21\u6570\u6700\u591a\u768420\u4e2asql\u8bed\u53e5\u548c\u8fd4\u56de\u8bb0\u5f55\u96c6\u6700\u591a\u768420\u4e2asql\u3002<BR>mysqldumpslow -t 10 -s t -g \u201cleft join\u201d host-slow.log<BR>\u8fd9\u4e2a\u662f\u6309\u7167\u65f6\u95f4\u8fd4\u56de\u524d10\u6761\u91cc\u9762\u542b\u6709\u5de6\u8fde\u63a5\u7684sql\u8bed\u53e5\u3002<\/DIV><br \/>\n<DIV>\u7528\u4e86\u8fd9\u4e2a\u5de5\u5177\u5c31\u53ef\u4ee5\u67e5\u8be2\u51fa\u6765\u90a3\u4e9bsql\u8bed\u53e5\u662f\u6027\u80fd\u7684\u74f6\u9888\uff0c\u8fdb\u884c\u4f18\u5316\uff0c\u6bd4\u5982\u52a0\u7d22\u5f15\uff0c\u8be5\u5e94\u7528\u7684\u5b9e\u73b0\u65b9\u5f0f\u7b49\u3002 <\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql\u6709\u4e00\u4e2a\u529f\u80fd\u5c31\u662f\u53ef\u4ee5log\u4e0b\u6765\u8fd0\u884c\u7684\u6bd4\u8f83\u6162\u7684sql\u8bed\u53e5\uff0c\u9ed8\u8ba4\u662f\u6ca1\u6709\u8fd9\u4e2alog\u7684\uff0c\u4e3a\u4e86\u5f00\u542f\u8fd9\u4e2a\u529f\u80fd\uff0c\u8981\u4fee\u6539my.cnf\u6216\u8005\u5728mysql\u542f\u52a8\u7684\u65f6\u5019\u52a0\u5165\u4e00\u4e9b\u53c2\u6570\u3002\u5982\u679c\u5728my.cnf\u91cc\u9762\u4fee\u6539\uff0c\u9700\u589e\u52a0\u5982\u4e0b\u51e0\u884c long_query_time = 1log-slow-queries = \/var\/youpath\/slow.loglog-queries-not-using-indexes long_query_time \u662f\u6307\u6267\u884c\u8d85\u8fc7\u591a\u4e45\u7684sql\u4f1a\u88ablog\u4e0b\u6765\uff0c\u8fd9\u91cc\u662f1\u79d2\u3002log-slow-queries \u8bbe\u7f6e\u628a\u65e5\u5fd7\u5199\u5728\u90a3\u91cc\uff0c\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u7cfb\u7edf\u4f1a\u7ed9\u4e00\u4e2a\u7f3a\u7701\u7684\u6587\u4ef6host_name-slow.log\uff0c\u6211\u751f\u6210\u7684log\u5c31\u5728mysql\u7684data\u76ee\u5f55log-queries-not-using-indexes \u5c31\u662f\u5b57\u9762\u610f\u601d\uff0clog\u4e0b\u6765\u6ca1\u6709\u4f7f\u7528\u7d22\u5f15\u7684query\u3002 \u628a\u4e0a\u8ff0\u53c2\u6570\u6253\u5f00\uff0c\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\uff0c\u5c31\u53ef\u4ee5\u5173\u6389\u4e86\uff0c\u7701\u5f97\u5f71\u54cd\u751f\u4ea7\u73af\u5883\u3002 \u63a5\u4e0b\u6765\u5c31\u662f\u5206\u6790\u4e86\uff0c\u6211\u8fd9\u91cc\u7684\u6587\u4ef6\u540d\u5b57\u53ebhost-slow.log\u3002\u5148mysqldumpslow \u2013help\u4ee5\u4e0b\uff0c\u4ffa\u4e3b\u8981\u7528\u7684\u662f-s ORDER what to sort by (t, at, l, al, r, ar etc), \u2018at\u2019 is default-t NUM just show the top n queries-g PATTERN grep: only consider stmts that include this string -s\uff0c\u662forder\u7684\u987a\u5e8f\uff0c\u8bf4\u660e\u5199\u7684\u4e0d\u591f\u8be6\u7ec6\uff0c\u4ffa\u7528\u4e0b\u6765\uff0c\u5305\u62ec\u770b\u4e86\u4ee3\u7801\uff0c\u4e3b\u8981\u6709c,t,l,r\u548cac,at,al,ar\uff0c\u5206\u522b\u662f\u6309\u7167query\u6b21\u6570\uff0c\u65f6\u95f4\uff0clock\u7684\u65f6\u95f4\u548c\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u6765\u6392\u5e8f\uff0c\u524d\u9762\u52a0\u4e86a\u7684\u65f6\u5012\u53d9-t\uff0c\u662ftop n\u7684\u610f\u601d\uff0c\u5373\u4e3a\u8fd4\u56de\u524d\u9762\u591a\u5c11\u6761\u7684\u6570\u636e-g\uff0c\u540e\u8fb9\u53ef\u4ee5\u5199\u4e00\u4e2a\u6b63\u5219\u5339\u914d\u6a21\u5f0f\uff0c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684 mysqldumpslow -s c -t 20 host-slow.logmysqldumpslow -s r -t &hellip; <a href=\"https:\/\/www.strongd.net\/?p=474\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u7528mysqldumpslow\u5206\u6790mysql\u7684slow query log<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[113],"class_list":["post-474","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-slow-query-log"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"predecessor-version":[{"id":896,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions\/896"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}