{"id":1163,"date":"2010-01-05T20:32:36","date_gmt":"2010-01-05T12:32:36","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=1163"},"modified":"2010-01-07T13:01:53","modified_gmt":"2010-01-07T05:01:53","slug":"mysql-slow-log-1","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2010\/01\/mysql-slow-log-1\/","title":{"rendered":"MySQL Slow Log\u6162\u65e5\u5fd7\u5206\u6790(\u4e00)"},"content":{"rendered":"<p>\u533b\u751f\u7ed9\u75c5\u4eba\u8bca\u65ad\u7684\u65f6\u5019\uff0c\u4e00\u822c\u4f1a\u4f7f\u7528\u542c\u8bca\u5668\u6765\u8bca\u65ad\u80ba\u90e8\u662f\u5426\u6b63\u5e38\u3002\u5982\u679c\u4f60\u7684MySQL\u51fa\u73b0\u4e86\u6027\u80fd\u95ee\u9898\uff0c\u7b2c\u4e00\u4e2a\u9700\u8981\u201c\u8bca\u65ad\u201d\u7684\u5c31\u662fslow log\uff08\u6162\u65e5\u5fd7\uff09\u4e86\u3002<\/p>\n<p>slow log\u6587\u4ef6\u5f88\u5c0f\uff0c\u4f7f\u7528more less\u7b49\u547d\u4ee4\u5c31\u8db3\u591f\u4e86\u3002\u5982\u679cslow log\u5f88\u5927\u600e\u4e48\u529e\uff1f\u8fd9\u91cc\u4ecb\u7ecdMySQL\u81ea\u5e26\u7684\u5de5\u5177mysqldumpslow\u6765\u5e2e\u4f60\u89e3\u6790\u6162\u65e5\u5fd7(\u4e5f\u53ef\u4ee5\u8df3\u8fc7\u672c\u6587\uff0c\u76f4\u63a5\u9605\u8bfb<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/mysqldumpslow.html\">Manual<\/a>)\u3002<\/p>\n<p><font color=\"red\">1. \u57fa\u672c\u4f7f\u7528<\/font> <\/p>\n<div class=\"mycode\">\n$mysqldumpslow slow.log > slow.dat<br \/>\n$more slow.dat\n<\/div>\n<p><!--more--><\/p>\n<p>\u8f93\u51fa\u7684\u6570\u636e\uff1a<\/p>\n<div class=\"mycode\">\nCount: 3  Time=62.67s (188s)  Lock=0.00s (0s)  Rows=1623770.7 (4871312), root[root]@localhost<br \/>\n  SELECT \/*!N SQL_NO_CACHE *\/ * FROM `feed_receive_0287`\n<\/div>\n<p>\u8fd9\u91cc\u6211\u4eec\u80fd\u591f\u83b7\u5f97\uff1a\u8fd9\u6761\u8bed\u53e5\u5728\u6ee1\u65e5\u5fd7\u4e2d\u7684\u51fa\u73b0\u6b21\u6570\u3001\u5e73\u5747\u6267\u884c\u65f6\u95f4\u3001\u603b\u5171\u6267\u884c\u65f6\u95f4\u3001row send\u7b49\u3002\u4f8b\u5982\uff1aSELECT \/*!N SQL_NO_CACHE *\/ * FROM `feed_receive_0287`\u4e00\u5171\u6267\u884c\u4e863\u6b21\uff0c\u5e73\u5747\u6bcf\u6b21\u4f7f\u752862\u79d2\u3002<\/p>\n<p>\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cmysqlslowdump\u7684\u8f93\u51fa\u7ed3\u679c\u4f1a\u4f7f\u7528N\u548cS\u4ee3\u66ffSQL\u4e2d\u51fa\u73b0\u7684\u6570\u5b57\u548c\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff1a\u5982\u4e0b\u6162\u65e5\u5fd7<\/p>\n<div class=\"mycode\">\n  SELECT COUNT(*) as counter FROM feed_receive f WHERE f.RATED_UID=21621 AND f.suspended=-1 AND f.rater_type=4 AND f.rate=-2 AND f.username=&#8221;orczhou.com&#8221;\n<\/div>\n<p>\u4f1a\u88abmysqlslowdump\u62bd\u8c61\u4e3a\uff1a<\/p>\n<div class=\"mycode\">\n  SELECT COUNT(*) as counter FROM feed_receive f WHERE f.RATED_UID=N AND f.suspended=-N AND f.rater_type=N AND f.rate=-N AND f.username=&#8221;S&#8221;\n<\/div>\n<p>\u5982\u679c\u60f3\u7981\u7528\u8fd9\u79cd\u62bd\u8c61\uff0c\u53ef\u4ee5\u4f7f\u7528-a\u53c2\u6570<\/p>\n<p><font color=\"red\">2. \u6392\u5e8f\u53c2\u6570<\/font> <\/p>\n<p>mysqlslowdump\u9ed8\u8ba4\u8f93\u51fa\u7ed3\u679c\u662f\u6309\u7167count\uff08SQL\u51fa\u73b0\u7684\u6b21\u6570\uff09\u6392\u5e8f\u7684\u3002\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u7684\u53c2\u6570\u63a7\u5236\uff1a<\/p>\n<style>\n.mytable {\nborder-color:#000000;\nborder-style:dashed;\nborder-width:1px 0 0 1px;\nborder-collapse:collapse;\nmargin-left:25px;\n}\n.mytd {\nborder-color:#000000;\nborder-style:dashed;\nborder-width:0 1px 1px 0;\ntext-align:center;\n}\n<\/style>\n<table width=\"500\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"center\" class=\"mytable\">\n<tr>\n<td class=\"mytd\">-s t<\/td>\n<td class=\"mytd\">\u6309\u603bquery time\u6392\u5e8f<\/td>\n<td class=\"mytd\">-s at<\/td>\n<td class=\"mytd\">\u6309\u5e73\u5747query time\u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td class=\"mytd\">-s l<\/td>\n<td class=\"mytd\">\u6309\u603blocktime\u6392\u5e8f<\/td>\n<td class=\"mytd\">-s al<\/td>\n<td class=\"mytd\">\u6309\u5e73\u5747lock time\u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td class=\"mytd\">-s s<\/td>\n<td class=\"mytd\">\u6309\u603brow send\u6392\u5e8f<\/td>\n<td class=\"mytd\">-s as<\/td>\n<td class=\"mytd\">\u6309\u5e73\u5747row send\u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td class=\"mytd\">-s c<\/td>\n<td class=\"mytd\">\u6309count\u6392\u5e8f<\/td>\n<td class=\"mytd\">&#8212;<\/td>\n<td class=\"mytd\">&#8212;<\/td>\n<\/tr>\n<\/table>\n<p>\u4f8b\u5982\uff1a<\/p>\n<div class=\"mycode\">\nmysqldumpslow -s at slow.log.old > slow.2.dat\t#\u6309\u7167\u5e73\u5747query time\u6392\u5e8f\u67e5\u770b\u65e5\u5fd7\n<\/div>\n<p><font color=\"red\">3. \u5176\u4ed6\u53c2\u6570<\/font><\/p>\n<table width=\"500\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"center\" class=\"mytable\">\n<tr>\n<td class=\"mytd\">-r<\/td>\n<td class=\"mytd\">\u5012\u7740\u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td class=\"mytd\">-a<\/td>\n<td class=\"mytd\">\u4e0d\u8981\u5c06\u6570\u5b57\u548c\u5b57\u7b26\u4e32\u62bd\u8c61\u6210N\u548cS<\/td>\n<\/tr>\n<tr>\n<td class=\"mytd\">-g<\/td>\n<td class=\"mytd\">\u4ec5\u4ec5\u5206\u6790\u76f8\u5339\u914d\u7684query<\/td>\n<\/tr>\n<\/table>\n<p><\/p>\n<p><font color=\"red\">4. \u5e38\u7528\u547d\u4ee4<\/font><\/p>\n<p>\u7531\u4e0a\u9762\u7684\u5e38\u7528\u53c2\u6570\u5c31\u53ef\u4ee5\u7ec4\u5408\u51fa\u5982\u4e0b\u7684\u5e38\u7528\u547d\u4ee4\uff1a<\/p>\n<div class=\"mycode\">\nmysqldumpslow -s t slow.log.old > slow.1.dat\t#\u6309\u7167query time\u6392\u5e8f\u67e5\u770b\u65e5\u5fd7<br \/>\nmysqldumpslow -s at slow.log.old > slow.2.dat\t#\u6309\u7167\u5e73\u5747query time\u6392\u5e8f\u67e5\u770b\u65e5\u5fd7<br \/>\nmysqldumpslow -a -s at slow.log.old > slow.3.dat\t#\u6309\u7167\u5e73\u5747query time\u6392\u5e8f\u5e76\u4e14\u4e0d\u62bd\u8c61\u6570\u5b57\u7684\u65b9\u5f0f\u6392\u5e8f<br \/>\nmysqldumpslow -a -s c slow.log.old > slow.4.dat #\u5b89\u88c5\u6267\u884c\u6b21\u6570\u6392\u5e8f\n<\/div>\n<p>\u53c2\u8003\uff1a<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/mysqldumpslow.html\">mysqldumpslow Manual<\/a><\/p>\n<p>\uff08\u5168\u6587\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u533b\u751f\u7ed9\u75c5\u4eba\u8bca\u65ad\u7684\u65f6\u5019\uff0c\u4e00\u822c\u4f1a\u4f7f\u7528\u542c\u8bca\u5668\u6765\u8bca\u65ad\u80ba\u90e8\u662f\u5426\u6b63\u5e38\u3002\u5982\u679c\u4f60\u7684MySQL\u51fa\u73b0\u4e86\u6027\u80fd\u95ee\u9898\uff0c\u7b2c\u4e00\u4e2a\u9700\u8981\u201c\u8bca\u65ad\u201d\u7684\u5c31\u662fslow log\uff08\u6162\u65e5\u5fd7\uff09\u4e86\u3002 slow log\u6587\u4ef6\u5f88\u5c0f\uff0c\u4f7f\u7528more less\u7b49\u547d\u4ee4\u5c31\u8db3\u591f\u4e86\u3002\u5982\u679cslow log\u5f88\u5927\u600e\u4e48\u529e\uff1f\u8fd9\u91cc\u4ecb\u7ecdMySQL\u81ea\u5e26\u7684\u5de5\u5177mysqldumpslow\u6765\u5e2e\u4f60\u89e3\u6790\u6162\u65e5\u5fd7(\u4e5f\u53ef\u4ee5\u8df3\u8fc7\u672c\u6587\uff0c\u76f4\u63a5\u9605\u8bfbManual)\u3002 1. \u57fa\u672c\u4f7f\u7528 $mysqldumpslow slow.log > slow.dat $more slow.dat<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6],"tags":[39],"class_list":["post-1163","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-slow-log"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=1163"}],"version-history":[{"count":30,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1163\/revisions"}],"predecessor-version":[{"id":1227,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1163\/revisions\/1227"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=1163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=1163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=1163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}