<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>记录与PHP的PK经历 &#187; mysqldumpslow</title>
	<atom:link href="http://www.pkphp.com/tag/mysqldumpslow/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pkphp.com</link>
	<description>PK with php!</description>
	<lastBuildDate>Fri, 27 May 2011 02:07:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>终于知道wordpress越来越慢的原因（一）</title>
		<link>http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/</link>
		<comments>http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 12:49:46 +0000</pubDate>
		<dc:creator>askie</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldumpslow]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[慢速]]></category>

		<guid isPermaLink="false">http://www.pkphp.com/?p=731</guid>
		<description><![CDATA[最近服务器速度越来越慢，有时候服务器负载经常到达十几甚至看到过二十。博客打开的速度也慢了起来，今天花...<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">mysql慢速(slow log)脚本分析</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F08%2Fwordpress-auto-blogroll-design%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">wordpress自助链接auto-blogroll插件设计细节！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F26%2Fwordpress-seo-v11%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">wordpress中文seo插件升级到V1.1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F11%2Fwordpress-plugin-auto-blogroll-v14-released%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">wordpress自助插件auto blogroll V1.4 发布!</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>最近服务器速度越来越慢，有时候服务器负载经常到达十几甚至看到过二十。博客打开的速度也慢了起来，今天花时间研究看看到底什么网站、什么数据库查询引起的问题。</p>
<p>首先在服务器端对mysql设置了慢速sql日志输出，详细的设置方法见：<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" target="_blank">mysql慢速(slow log)脚本分析</a></p>
<p>使用mysql自带的慢速日志查询工具对日志进行分析，按照最多查询记录排序，发现如下sql是查询出记录最多的，这条语句居然查出来9946条记录，俄地个乖乖，不慢才怪：</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">Count</span>: 18  <span style="color: #0000ff;">Time</span>=4294967294.94s (-1s)  Lock=0.00s (0s)  <span style="color: #0000ff;">Rows</span>=552.6 (9946), 2users@localhost</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">SELECT</span> post_title, DAYOFMONTH(post_date) <span style="color: #0000ff;">as</span> dom <span style="color: #0000ff;">FROM</span> wp_posts <span style="color: #0000ff;">WHERE</span> <span style="color: #0000ff;">YEAR</span>(post_date) = <span style="color: #006080;">'S'</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">AND</span> <span style="color: #0000ff;">MONTH</span>(post_date) = <span style="color: #006080;">'S'</span> <span style="color: #0000ff;">AND</span> post_date &lt; <span style="color: #006080;">'S'</span> <span style="color: #0000ff;">AND</span> post_type = <span style="color: #006080;">'S'</span> <span style="color: #0000ff;">AND</span> post_status = <span style="color: #006080;">'S'</span></pre>
</div>
</div>
<p>这个是mysqldumpslow出来的统计排列第一的结果。然后进入日志查找具体的sql语句发现：</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">use</span> abc;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">SELECT</span> post_title, DAYOFMONTH(post_date) <span style="color: #0000ff;">as</span> dom <span style="color: #0000ff;">FROM</span> wp_posts</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">WHERE</span> <span style="color: #0000ff;">YEAR</span>(post_date) = <span style="color: #006080;">'2008'</span> <span style="color: #0000ff;">AND</span> <span style="color: #0000ff;">MONTH</span>(post_date) = <span style="color: #006080;">'10'</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">AND</span> post_date &lt; <span style="color: #006080;">'2008-10-05 13:09:33'</span> <span style="color: #0000ff;">AND</span> post_type = <span style="color: #006080;">'post'</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">AND</span> post_status = <span style="color: #006080;">'publish'</span>;</pre>
</div>
</div>
<p>这样的类似语句很多，变化的都是时间，看了这个马上就明白这条语句不就是wordpress存档查询么！去看了一下wordpress，侧边栏输出了所有存档（archive）链接，我猜测就是因为存档链接的输出引起的这些sql查询。马上回到后台，关闭了所有的存档输出，再检测一段时间的mysql，发现这样的语句消失了！</p>
<p>终于找到了原因了，服务器负载有所降低，看来以后wordpress不能输出存档链接了！其实还有一个办法就是静态化日志链接也可以解决这个问题，我的做法是直接静态化了首页，即使首页输出了存档链接也不会引起查询。这样做也能降低一部分mysql查询。<br />
<h3 class="bsuite_related">Related items</h3>
<ul class="bsuite_related">
<li><a href='http://www.pkphp.com/2008/10/04/mysql-slow-log/'>mysql慢速(slow log)脚本分析</a></li>
<li><a href='http://www.pkphp.com/2008/08/16/mysql%e4%b8%ad%e8%ae%be%e7%bd%ae%e8%87%aa%e5%a2%9e%e5%ad%97%e6%ae%b5/'>MySQL中设置自增字段</a></li>
<li><a href='http://www.pkphp.com/2008/08/16/mysql-optimization-script/'>mysql优化脚本！</a></li>
<li><a href='http://www.pkphp.com/2008/07/28/mysql%e9%9a%8f%e6%9c%ba%e6%9f%a5%e8%af%a2%e8%be%93%e5%87%ba%e6%95%b0%e6%8d%ae%e8%af%ad%e5%8f%a5/'>mysql随机查询输出数据语句</a></li>
<li><a href='http://www.pkphp.com/2010/12/11/mysql%e4%b8%ad%e7%9a%84%e8%a1%a8%e6%98%be%e7%a4%ba%e2%80%9c%e4%bd%bf%e7%94%a8%e4%b8%ad%e2%80%9d%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95%ef%bc%81/'>mysql中的表显示“使用中”解决办法！</a></li>
</ul>
<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="http://www.pkphp.com/" style="font-size: 13px;">http://www.pkphp.com/</a>(2)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="WordPress " style="font-size: 13px;">WordPress </a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress 慢" style="font-size: 13px;">wordpress 慢</a>(63)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="Wordpress 负载" style="font-size: 13px;">WordPress 负载</a>(18)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress 发布日志慢" style="font-size: 13px;">wordpress 发布日志慢</a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="ajax tree 越来越慢" style="font-size: 13px;">ajax tree 越来越慢</a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress php 慢" style="font-size: 13px;">wordpress php 慢</a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress 越来越慢" style="font-size: 13px;">wordpress 越来越慢</a>(3)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="PHP 慢" style="font-size: 13px;">PHP 慢</a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress慢" style="font-size: 13px;">wordpress慢</a>(4)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress越來越慢" style="font-size: 13px;">wordpress越來越慢</a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress打开慢" style="font-size: 13px;">wordpress打开慢</a>(4)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress降低sql链接" style="font-size: 13px;">wordpress降低sql链接</a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress 记录 数据库 慢" style="font-size: 13px;">wordpress 记录 数据库 慢</a>(1)<a href="http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/" title="wordpress 打开 慢" style="font-size: 13px;">wordpress 打开 慢</a>(2)<br /><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">mysql慢速(slow log)脚本分析</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F08%2Fwordpress-auto-blogroll-design%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">wordpress自助链接auto-blogroll插件设计细节！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F26%2Fwordpress-seo-v11%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">wordpress中文seo插件升级到V1.1</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F11%2Fwordpress-plugin-auto-blogroll-v14-released%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">wordpress自助插件auto blogroll V1.4 发布!</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件" rel="nofollow">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><div id="relatedlinks_container_div"></div>
<script language=javascript defer>
  var escFun = window.encodeURIComponent ? window.encodeURIComponent : escape;
  var relatedlinks_js = document.createElement("script");
  relatedlinks_js.setAttribute("charset", "utf-8");
  relatedlinks_js.src = "http://relatedlinks.googlelabs.com/client/client.js?url=" +
      escFun(document.URL) + "&referrer=" + escFun(document.referrer) +
      "&relatedlinks_id=10098_5845376649736343543&title=" + escFun(document.title);
  document.getElementsByTagName("head")[0].appendChild(relatedlinks_js);
</script></p> ]]></content:encoded>
			<wfw:commentRss>http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mysql慢速(slow log)脚本分析</title>
		<link>http://www.pkphp.com/2008/10/04/mysql-slow-log/</link>
		<comments>http://www.pkphp.com/2008/10/04/mysql-slow-log/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 12:34:11 +0000</pubDate>
		<dc:creator>askie</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[mysqldumpslow]]></category>
		<category><![CDATA[slow]]></category>

		<guid isPermaLink="false">http://www.pkphp.com/?p=724</guid>
		<description><![CDATA[mysql有一个功能就是可以log下来运行的比较慢的sql语句，默认是没有这个log的，为了开启这个功能，
要修改...<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">终于知道wordpress越来越慢的原因（一）</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F16%2Fmysql-optimization-script%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">mysql优化脚本！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F16%2Fmysql%25E4%25B8%25AD%25E8%25AE%25BE%25E7%25BD%25AE%25E8%2587%25AA%25E5%25A2%259E%25E5%25AD%2597%25E6%25AE%25B5%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL中设置自增字段</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F07%2F28%2Fmysql%25E9%259A%258F%25E6%259C%25BA%25E6%259F%25A5%25E8%25AF%25A2%25E8%25BE%2593%25E5%2587%25BA%25E6%2595%25B0%25E6%258D%25AE%25E8%25AF%25AD%25E5%258F%25A5%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">mysql随机查询输出数据语句</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>mysql有一个功能就是可以log下来运行的比较慢的sql语句，默认是没有这个log的，为了开启这个功能，<br />
要修改my.cnf或者在mysql启动的时候加入一些参数。如果在my.cnf里面修改，需增加如下几行</p>
<p><code>long_query_time = 1<br />
log-slow-queries = /var/youpath/slow.log<br />
log-queries-not-using-indexes</code></p>
<p>long_query_time 是指执行超过多久的sql会被log下来，这里是1秒。<br />
log-slow-queries 设置把日志写在那里，可以为空，系统会给一个缺省的文件host_name-slow.log，<br />
log-queries-not-using-indexes 就是字面意思，log下来没有使用索引的query。</p>
<p>把上述参数打开，运行一段时间，就可以关掉了。</p>
<p>接下来就是分析了，这里的文件名字叫host-slow.log。<br />
先mysqldumpslow –help以下，e它主要用的是<br />
<code>-s ORDER what to sort by (t, at, l, al, r, ar etc), ‘at’ is default<br />
-t NUM just show the top n queries<br />
-g PATTERN grep: only consider stmts that include this string</code></p>
<p>-s，是order的顺序，说明写的不够详细，主要有<br />
c,t,l,r和ac,at,al,ar，分别是按照query次数，时间，lock的时间和返回的记录数来排序，前面加了a的时倒叙<br />
-t，是top n的意思，即为返回前面多少条的数据<br />
-g，后边可以写一个正则匹配模式，大小写不敏感的</p>
<p><code>mysqldumpslow -s c -t 20 host-slow.log<br />
mysqldumpslow -s r -t 20 host-slow.log</code></p>
<p>上述命令可以看出访问次数最多的20个sql语句和返回记录集最多的20个sql。<br />
<code>mysqldumpslow -t 10 -s t -g “left join” host-slow.log</code><br />
这个是按照时间返回前10条里面含有左连接的sql语句。</p>
<p>用了这个工具就可以查询出来那些sql语句是性能的瓶颈，进行优化，比如加索引，该应用的实现方式等。 </p>
<p><code>mysqldumpslow  -s c -t 10  /tmp/slow_query.log</code><br />
<h3 class="bsuite_related">Related items</h3>
<ul class="bsuite_related">
<li><a href='http://www.pkphp.com/2008/10/05/why-wordpress-so-slow/'>终于知道wordpress越来越慢的原因（一）</a></li>
<li><a href='http://www.pkphp.com/2008/08/16/mysql%e4%b8%ad%e8%ae%be%e7%bd%ae%e8%87%aa%e5%a2%9e%e5%ad%97%e6%ae%b5/'>MySQL中设置自增字段</a></li>
<li><a href='http://www.pkphp.com/2008/08/16/mysql-optimization-script/'>mysql优化脚本！</a></li>
<li><a href='http://www.pkphp.com/2008/07/28/mysql%e9%9a%8f%e6%9c%ba%e6%9f%a5%e8%af%a2%e8%be%93%e5%87%ba%e6%95%b0%e6%8d%ae%e8%af%ad%e5%8f%a5/'>mysql随机查询输出数据语句</a></li>
<li><a href='http://www.pkphp.com/2010/12/11/mysql%e4%b8%ad%e7%9a%84%e8%a1%a8%e6%98%be%e7%a4%ba%e2%80%9c%e4%bd%bf%e7%94%a8%e4%b8%ad%e2%80%9d%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95%ef%bc%81/'>mysql中的表显示“使用中”解决办法！</a></li>
</ul>
<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql log-queries-not-using-indexes" style="font-size: 13px;">mysql log-queries-not-using-indexes</a>(3)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql log sql 语句" style="font-size: 13px;">mysql log sql 语句</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql 慢" style="font-size: 13px;">mysql 慢</a>(4)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql log-slow-queries" style="font-size: 13px;">mysql log-slow-queries</a>(3)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql log 为空" style="font-size: 13px;">mysql log 为空</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="php mysql 慢" style="font-size: 13px;">php mysql 慢</a>(3)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="php mysql慢" style="font-size: 13px;">php mysql慢</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="apache php slowly" style="font-size: 13px;">apache php slowly</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql" style="font-size: 13px;">mysql</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="PHP 慢" style="font-size: 13px;">PHP 慢</a>(2)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysqldumpslow" style="font-size: 13px;">mysqldumpslow</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql slow log设置" style="font-size: 13px;">mysql slow log设置</a>(2)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql slow query 脚本分析" style="font-size: 13px;">mysql slow query 脚本分析</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="mysql slow log分析工具" style="font-size: 13px;">mysql slow log分析工具</a>(1)<a href="http://www.pkphp.com/2008/10/04/mysql-slow-log/" title="wordpress slow" style="font-size: 13px;">wordpress slow</a>(1)<br /><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F05%2Fwhy-wordpress-so-slow%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">终于知道wordpress越来越慢的原因（一）</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F16%2Fmysql-optimization-script%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">mysql优化脚本！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F08%2F16%2Fmysql%25E4%25B8%25AD%25E8%25AE%25BE%25E7%25BD%25AE%25E8%2587%25AA%25E5%25A2%259E%25E5%25AD%2597%25E6%25AE%25B5%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL中设置自增字段</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.pkphp.com%2F2008%2F07%2F28%2Fmysql%25E9%259A%258F%25E6%259C%25BA%25E6%259F%25A5%25E8%25AF%25A2%25E8%25BE%2593%25E5%2587%25BA%25E6%2595%25B0%25E6%258D%25AE%25E8%25AF%25AD%25E5%258F%25A5%2F&from=http%3A%2F%2Fwww.pkphp.com%2F2008%2F10%2F04%2Fmysql-slow-log%2F" rel="nofollow">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">mysql随机查询输出数据语句</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件" rel="nofollow">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.pkphp.com/2008/10/04/mysql-slow-log/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

