<?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>MySQL支持 &#187; MySQL TIPS/FAQ</title>
	<atom:link href="http://www.mysqlsupport.cn/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlsupport.cn</link>
	<description>MySQL支持，提供专业技术支持性能调优，架构设计</description>
	<lastBuildDate>Thu, 19 Aug 2010 05:35:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Innodb Log写入方式分析</title>
		<link>http://www.mysqlsupport.cn/analyzing-the-distribution-of-innodb-log-file-writes/</link>
		<comments>http://www.mysqlsupport.cn/analyzing-the-distribution-of-innodb-log-file-writes/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 05:35:45 +0000</pubDate>
		<dc:creator>tom_fans</dc:creator>
				<category><![CDATA[Innodb]]></category>
		<category><![CDATA[Linux/Unix技术]]></category>
		<category><![CDATA[MySQL TIPS/FAQ]]></category>
		<category><![CDATA[innodb log]]></category>

		<guid isPermaLink="false">http://www.mysqlsupport.cn/?p=174</guid>
		<description><![CDATA[作者/译者：王佳隆　来源:　http://www.mysqlsupport.cn/ 联系方式：enjoylonely#live.cn  转载请注:译者和出处，并且不能用于商业用途，违者必究.
原文URL：http://www.mysqlperformanceblog.com/2010/07/16/analyzing-the-distribution-of-innodb-log-file-writes/
    最近我分析了一下Innodb是如何写多个日志的。我这里有个流量比较高的MySQL系统，使用的是Percona XtraDB存储引擎，
我使用strace命令分别跟踪了innodb如何去日志文件的。通常来说，innodb是以512bytes的大小来写入日志的。
关于这个可以参考：Mark Callaghan explained this and some of its performance implications 。那么innodb什么时候情况下会以大于512bytes者小于512bytes的请求写到日志里呢？
首先，我通过lsof命令找出日志的文件描述符(handle).

# lsof -p $(pidof mysqld) &#124; grep ib_log
mysqld  29772 mysql    8uW  REG                8,2   268435456   7143989 /var/lib/mysql/ib_logfile0
mysqld  29772 mysql    9uW  REG                8,2   268435456   7143993 /var/lib/mysql/ib_logfile1

我们可以看到2个日志的handle为8和9，现在我们需要捕获innodb是如何写这2个日志的相关信息。Innodb轮循写日志就是通过这个文件描述符.
The following grabs the write sizes out of 100k calls to pwrite() and aggregates them：
# strace -f -p [...]]]></description>
			<content:encoded><![CDATA[<p><strong>作者</strong><strong>/</strong><strong>译者：王佳隆　来源</strong><strong>:</strong><strong>　</strong><strong>http://www.mysqlsupport.cn/ </strong><strong>联系方式：</strong><strong>enjoylonely#live.cn  </strong><strong>转载请注</strong><strong>:</strong><strong>译者和出处，并且不能用于商业用途，违者必究</strong><strong>.</strong></p>
<p>原文URL：http://www.mysqlperformanceblog.com/2010/07/16/analyzing-the-distribution-of-innodb-log-file-writes/</p>
<p>    最近我分析了一下Innodb是如何写多个日志的。我这里有个流量比较高的MySQL系统，使用的是Percona XtraDB存储引擎，</p>
<p>我使用strace命令分别跟踪了innodb如何去日志文件的。通常来说，innodb是以512bytes的大小来写入日志的。</p>
<p>关于这个可以参考：<a href="http://mysqlha.blogspot.com/2009/06/buffered-versus-direct-io-for-innodb.html" target="_blank">Mark Callaghan explained this and some of its performance implications</a> 。那么innodb什么时候情况下会以大于512bytes者小于512bytes的请求写到日志里呢？</p>
<p>首先，我通过lsof命令找出日志的文件描述符(handle).</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># lsof -p $(pidof mysqld) | grep ib_log
mysqld  29772 mysql    8uW  REG                8,2   268435456   7143989 /var/lib/mysql/ib_logfile0
mysqld  29772 mysql    9uW  REG                8,2   268435456   7143993 /var/lib/mysql/ib_logfile1</pre></div></div>

<p>我们可以看到2个日志的handle为8和9，现在我们需要捕获innodb是如何写这2个日志的相关信息。Innodb轮循写日志就是通过这个文件描述符.</p>
<p>The following grabs the write sizes out of 100k calls to pwrite() and aggregates them：</p>
<p># strace -f -p $(pidof mysqld) -e pwrite -s1 -xx 2&gt;&amp;1 \</p>
<p>   | grep &#8216;pwrite([89],&#8217; |head -n 100000 \</p>
<p>   | awk &#8216;{writes[$5]++}END{for(w in writes){print w, &#8221; &#8220;, writes[w]}}&#8217;</p>
<p>本来我可以写一个更好的脚本来捕获信息，但是下面的信息对我来说已经足够了。</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&lt;strong&gt;bytes        count&lt;/strong&gt;
512           44067
1024         30740
1536         15221
2048         7094
2560         1810
3072         570
3584         219
4096         112
4608         39
5120         23
5632         16
6144         15
6656         5
7168         3
7680         8
8192         2
8704         2
9216         1
9728         2
10240       1
10752       2
11264       1
11776       1
14848       1
15360       1
15872       2
16384       4
16896       4
17408       2
17920       2
18432       2
18944       8
19456       7
19968       4
20480       4
21504       1
22016       2
24064       1
40960       1</pre></div></div>

<p>总的来说，大致有3/4是以512和1024字节写入的。那么这到底什么意思呢？这里有很多有趣的而且复杂的东西需要我们去研究。</p>
<p> 1. 我们可以看到，大部分的写入都小于4K。但是我们知道操作系统的page大小是4K的。如果要写入的page不在cache中，那么这个page最开始需要读出，然后再修改，最后再写回到磁盘。vadim曾经过做做一些测试，如果要性能最好，那么日志要在OS的cache中。</p>
<p> 2.这台MySQL的innodb_flush_log_at_trx_commit设置是2.这就说明每个事务都会有一个日志写入请求，这个和设置为1是一样的。但是如果设置成0，那么写入的方法就大不相同&#8212;这个时候写入请求会累计到一定程度，然后一起写入。</p>
<p> 3.那么如果说log buffer小于一个事务要写的日志大小怎么办？这是另外一个需要研究的主题了。目前我还不清楚。</p>
<p>4.从上面的信息来看，是否可以很容易知道log buffer大小应该给多少呢？最大的写入小于40K，这好像可以说明分配64K给log buffer就已经足够了。这是真的吗？我们需要去测试才可以知道。peter以前和我谈过这个问题，log buffer背后的机制其实是很复杂的，到底log buffer需要保留多少空间给写操作。这些都需要更深入的研究。但是有一点可以确认，即使最大的写入操作不是很大的情况下，如果log buffer设置太小，性能肯定是不好的，而且会造成而外的锁。这个问题或许我们同样需要去研究。</p>
<p>最后，研究innodb是如何写日志的很容易，但是事实上innodb redo log机制是很复杂的，有时候我们很难说去猜想应该是什么样的，而应该去更深入的研究才可以知道的更多。也许我们可以按照上面这种步骤去研究不同LOG buufer大小，不同的日志参数设置，以及不同的服务器负载的情况下innodb到底是如何来写入日志的。</p>
<p>参考地址：http://mysqlha.blogspot.com/2009/06/buffered-versus-direct-io-for-innodb.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/analyzing-the-distribution-of-innodb-log-file-writes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mysqldump 的Tips</title>
		<link>http://www.mysqlsupport.cn/mysqldump-%e7%9a%84tips/</link>
		<comments>http://www.mysqlsupport.cn/mysqldump-%e7%9a%84tips/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 14:34:28 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>

		<guid isPermaLink="false">http://www.mysqlsupport.cn/?p=172</guid>
		<description><![CDATA[作者：吴炳锡　来源:http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注:译者和出处，并且不能用于商业用途，违者必究.
只导出表结构：
 mysqldump   -d &#8211;trigger=false
只导出存储过程：
mysqldump -f  -Rtdn &#8211;triggers=false
只导出触发器：
 mysqldump -f  -tdn &#8211;triggers
只导出事件：
 mysqldump -f  -Etdn &#8211;triggers=false
只导出数据：
mysqldump -f  &#8211;single-transaction &#8211;triggers=false  -t
]]></description>
			<content:encoded><![CDATA[<p><strong>作者：吴炳锡　来源:http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注:译者和出处，并且不能用于商业用途，违者必究.</strong></p>
<p>只导出表结构：<br />
 mysqldump   -d &#8211;trigger=false<br />
只导出存储过程：<br />
mysqldump -f  -Rtdn &#8211;triggers=false<br />
只导出触发器：<br />
 mysqldump -f  -tdn &#8211;triggers<br />
只导出事件：<br />
 mysqldump -f  -Etdn &#8211;triggers=false<br />
只导出数据：<br />
mysqldump -f  &#8211;single-transaction &#8211;triggers=false  -t</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/mysqldump-%e7%9a%84tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>合理使用MySQL的Limit进行分页</title>
		<link>http://www.mysqlsupport.cn/optimize_limit_sql/</link>
		<comments>http://www.mysqlsupport.cn/optimize_limit_sql/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 10:11:41 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>
		<category><![CDATA[MySQL优化]]></category>
		<category><![CDATA[SQL优化]]></category>

		<guid isPermaLink="false">http://www.mysqlsupport.cn/?p=81</guid>
		<description><![CDATA[     作者：吴炳锡　来源：http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。      
         今天看一个水友说他的MySQL现在变的很慢。问什么情况时。说单表超过2个G的一个MyISAM。真垃圾的回答方式。
    简单答复：换一个强劲的服务器。换服务器很管用的：）
………
       最终让取到慢查询：

    SELECT * FROM pw_gbook WHERE uid='N' ORDER BY postdate DESC LIMIT N,N;

如：

   SELECT * FROM pw_gbook WHERE uid='48' ORDER BY postdate DESC LIMIT 1275480,20;

        看到这个语句我都吐血了（BT的PHPWIND分页啊，这个语句是PHP初学者写出来的还正常，但PHPWIND那么成熟的社区了还有这样的问题）。
        我这里简单说一下LIMIT的原理。这里以LIMIT N,M为基础：LIMIT首先要找查N+M行，然后从N行处，取M行。那么这样的SQL对一次查询1275500一个操作应该是一个昂贵的开销。对于LIMIT这类的优化，第一个目标就是让N变的尽可能的小或是不用。
     怎么才能使这个N尽可能小呢。我们能做的其实就是用相对的值，给分页一个提示。如现在我们看的是第5页，看完看想看第6页，第6页同样显示是20条记录。我们就可以想到，以这个例子为准：我们可以肯定的是第6页的日值应小于第5页的，如果第5页的最小日值为：2009-11-4，那我们就可以用：

     SELECT * FROM pw_gbook WHERE uid='48' and postdate&#38;lt;’2009-11-1’ ORDER BY postdate DESC LIMIT  20;

这样来查询第6页的内容。同样对于查看第4页的内容（假设第5页的最大日期为：2009-11-3）则第4页的内容为：

     SELECT * FROM [...]]]></description>
			<content:encoded><![CDATA[<p>     作者：吴炳锡　来源：http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。      </p>
<p>         今天看一个水友说他的MySQL现在变的很慢。问什么情况时。说单表超过2个G的一个MyISAM。真垃圾的回答方式。</p>
<p>    简单答复：换一个强劲的服务器。换服务器很管用的：）</p>
<p>………<br />
       最终让取到慢查询：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">    <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'N'</span> <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span> N<span style="color: #000033;">,</span>N<span style="color: #000033;">;</span></pre></div></div>

<p>如：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">   <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">1275480</span><span style="color: #000033;">,</span><span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>        看到这个语句我都吐血了（BT的PHPWIND分页啊，这个语句是PHP初学者写出来的还正常，但PHPWIND那么成熟的社区了还有这样的问题）。<br />
        我这里简单说一下LIMIT的原理。这里以LIMIT N,M为基础：LIMIT首先要找查N+M行，然后从N行处，取M行。那么这样的SQL对一次查询1275500一个操作应该是一个昂贵的开销。对于LIMIT这类的优化，第一个目标就是让N变的尽可能的小或是不用。<br />
     怎么才能使这个N尽可能小呢。我们能做的其实就是用相对的值，给分页一个提示。如现在我们看的是第5页，看完看想看第6页，第6页同样显示是20条记录。我们就可以想到，以这个例子为准：我们可以肯定的是第6页的日值应小于第5页的，如果第5页的最小日值为：2009-11-4，那我们就可以用：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">     <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #CC0099; font-weight: bold;">and</span> postdate<span style="color: #CC0099;">&amp;</span>lt<span style="color: #000033;">;</span>’<span style="color: #008080;">2009</span><span style="color: #CC0099;">-</span><span style="color: #008080;">11</span><span style="color: #CC0099;">-</span><span style="color: #008080;">1</span>’ <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span>  <span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>这样来查询第6页的内容。同样对于查看第4页的内容（假设第5页的最大日期为：2009-11-3）则第4页的内容为：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">     <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #CC0099; font-weight: bold;">and</span> postdate<span style="color: #CC0099;">&amp;</span>gt<span style="color: #000033;">;</span>’<span style="color: #008080;">2009</span><span style="color: #CC0099;">-</span><span style="color: #008080;">11</span><span style="color: #CC0099;">-</span><span style="color: #008080;">3</span>’ <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span>  <span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>         这是一个基本的思想。接下来讨论一下怎么展现的问题。</p>
<p>         再说一下这种业务的SQL怎么实现：对于分页的展示可以用多用类型。这里说三种常用的类型：</p>
<p>第一种：显示“上一页” “下一页”这种类型</p>
<p>         这种方式相对简单也就出现了我们看到那种SQL不思考的写法。合理的做法：</p>
<p>         第一页：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">     <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span>  <span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>         第二页：根据第一页的postdate进行查询如：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">      <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span>  <span style="color: #CC0099; font-weight: bold;">and</span> postdate<span style="color: #CC0099;">&amp;</span>lt<span style="color: #000033;">;</span>’<span style="color: #008080;">2009</span><span style="color: #CC0099;">-</span><span style="color: #008080;">11</span><span style="color: #CC0099;">-</span><span style="color: #008080;">3</span>’  <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span>  <span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>         为什么说这个简单呢，这个不存在跳页的问题。接下来这种就存在一个跳页的问题了。</p>
<p>第二种：显示 “ 1,2,3,4,5…”</p>
<p>         第一页： 还是以第一页的方式实现：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">         <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span>  <span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>         第二页：和原来一样。如果跳页，如从第二页跳到第5页，这里有一个第二页的最小日期为：2009-11-3（假设值，可以由第二页的程序查询得到），第二到第5，差2页，每页20条记录，那么就可以用：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span>  <span style="color: #CC0099; font-weight: bold;">and</span> postdate<span style="color: #CC0099;">&amp;</span>lt<span style="color: #000033;">;</span>’<span style="color: #008080;">2009</span><span style="color: #CC0099;">-</span><span style="color: #008080;">11</span><span style="color: #CC0099;">-</span><span style="color: #008080;">3</span>’  <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span>  <span style="color: #008080;">40</span>，<span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>        看到这里明白为什么大型网站的分页不是一下标识出来完了，让都能点了吧。也不会给你一个框让你输入一个页跳过去了。如果跳的页面过多，也就存在N值过大的问题了。所以要想办法必免。</p>
<p>第三种：显示 “1，2，3，4，5，…. 末页” 或是 “首页，&lt;&lt;100,101,102,103 &gt;&gt;末页”</p>
<p>这里有一个特殊的一地方：</p>
<p>别的页面的跳转的上面一样。这里就加一个末页，这里又分两种情况，如果知道最后一页是多少页，也就知道了前一页的最小日期（分页提示值），这样就可以用上面的方法查看最后一页的内容（会出现不足20条的现象），另一种，我就不知道最后是第几页，我就是想看看最后什么样子，那么就可以用（一定是显示20条）：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">ASC</span> <span style="color: #990099; font-weight: bold;">limit</span> <span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>         首页这里就不在说了。</p>
<p>        </p>
<p>         具体怎么实现搞明白了，就可以做PHP代码的修改了。稍稍修改一下，就会带来意想不到的效果。</p>
<p> </p>
<p>这里只是一个通用的分页处理方法。不同的业务有可能还有不同的方法处理。如果在条件可能和情况可以考用:between … and .. 带代替limit分页操作。</p>
<p>第三种方法：        <br />
        简单的逻辑转换。</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">   <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">1275480</span><span style="color: #000033;">,</span><span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p>  转换成：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">   <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> pw_gbook <span style="color: #990099; font-weight: bold;">WHERE</span> id<span style="color: #CC0099;">&gt;</span><span style="color: #008080;">1275480</span> <span style="color: #CC0099; font-weight: bold;">and</span>  uid<span style="color: #CC0099;">=</span><span style="color: #008000;">'48'</span> <span style="color: #990099; font-weight: bold;">ORDER BY</span> postdate <span style="color: #990099; font-weight: bold;">DESC</span> <span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">20</span><span style="color: #000033;">;</span></pre></div></div>

<p><a href="http://www.mysqlsupport.cn">本站提供专业：PHPWIND优化，DISCUZ优化，DRUPAL优化 及相关咨询</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/optimize_limit_sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Relay log read failure的处理</title>
		<link>http://www.mysqlsupport.cn/relay-log-read-failure/</link>
		<comments>http://www.mysqlsupport.cn/relay-log-read-failure/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 08:35:47 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>
		<category><![CDATA[MySQL同步]]></category>
		<category><![CDATA[MySQL基础]]></category>
		<category><![CDATA[同步中的Bug]]></category>

		<guid isPermaLink="false">http://www.mysqlsupport.cn/?p=59</guid>
		<description><![CDATA[作者：吴炳锡　来源：http://www.mysqlsupport.cn/ 联系方式：select unhex(’777562696E67786940676D61696C2E636F6D’); 载请注明作/译者和出处，并且不能用于商业用途，违者必究。
       众所周知MySQL5.1的Replication是比较烂的。MySQL的每一个版本更新关于同步方面每次都是可以看到一大堆。但MySQL 5.1性能是比较突出的。所以经不住诱惑使用MySQL 5.1。所以也要经常遇到一些Bug。如： 

mysql&#62; show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.10.118
                  Master_User: repl_wu
                  Master_Port: 3306
                Connect_Retry: 30
              Master_Log_File: mysql-bin.005121
          Read_Master_Log_Pos: 64337286
               Relay_Log_File: relay-bin.003995
                Relay_Log_Pos: 18446697137031827760
        Relay_Master_Log_File: mysql-bin.005121
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 1594
                   Last_Error: Relay log read failure: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>作者：吴炳锡　来源：</strong><a href="http://www.mysqlsupport.cn/"><strong>http://www.mysqlsupport.cn/</strong></a><strong> </strong><strong>联系方式：</strong><strong>select unhex(’777562696E67786940676D61696C2E636F6D’); </strong><strong>载请注明作</strong><strong>/</strong><strong>译者和出处，并且不能用于商业用途，违者必究。</strong><br />
       众所周知MySQL5.1的Replication是比较烂的。MySQL的每一个版本更新关于同步方面每次都是可以看到一大堆。但MySQL 5.1性能是比较突出的。所以经不住诱惑使用MySQL 5.1。所以也要经常遇到一些Bug。如： </p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">show</span> slave <span style="color: #990099; font-weight: bold;">status</span>\G
<span style="color: #CC0099;">***************************</span> <span style="color: #008080;">1.</span> row <span style="color: #CC0099;">***************************</span>
               Slave_IO_State: Waiting for master <span style="color: #990099; font-weight: bold;">to</span> send event
                  Master_Host: 192.168.10.118
                  Master_User: repl_wu
                  Master_Port: <span style="color: #008080;">3306</span>
                Connect_Retry: <span style="color: #008080;">30</span>
              Master_Log_File: mysql<span style="color: #CC0099;">-</span><span style="color: #000099;">bin</span>.005121
          Read_Master_Log_Pos: <span style="color: #008080;">64337286</span>
               Relay_Log_File: relay<span style="color: #CC0099;">-</span><span style="color: #000099;">bin</span>.003995
                Relay_Log_Pos: <span style="color: #008080;">18446697137031827760</span>
        Relay_Master_Log_File: mysql<span style="color: #CC0099;">-</span><span style="color: #000099;">bin</span>.005121
             Slave_IO_Running: Yes
            Slave_SQL_Running: <span style="color: #990099; font-weight: bold;">No</span>
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: <span style="color: #008080;">1594</span>
                   Last_Error: Relay <span style="color: #000099;">log</span> <span style="color: #990099; font-weight: bold;">read</span> failure: Could <span style="color: #CC0099; font-weight: bold;">not</span> parse relay <span style="color: #000099;">log</span> event entry. The possible reasons are: the master<span style="color: #008000;">'s binary log is corrupted (you can check this by running '</span>mysqlbinlog<span style="color: #008000;">' on the binary log), the slave'</span>s relay <span style="color: #000099;">log</span> <span style="color: #CC0099; font-weight: bold;">is</span> corrupted <span style="color: #FF00FF;">&#40;</span>you can <span style="color: #990099; font-weight: bold;">check</span> this by running <span style="color: #008000;">'mysqlbinlog'</span> <span style="color: #990099; font-weight: bold;">on</span> the relay <span style="color: #000099;">log</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> a network problem<span style="color: #000033;">,</span> <span style="color: #CC0099; font-weight: bold;">or</span> a bug <span style="color: #990099; font-weight: bold;">in</span> the master<span style="color: #008000;">'s or slave'</span>s MySQL code. <span style="color: #009900;">If</span> you want <span style="color: #990099; font-weight: bold;">to</span> <span style="color: #990099; font-weight: bold;">check</span> the master<span style="color: #008000;">'s binary log or slave'</span>s relay <span style="color: #000099;">log</span><span style="color: #000033;">,</span> you will be able <span style="color: #990099; font-weight: bold;">to</span> know their names by issuing <span style="color: #008000;">'SHOW SLAVE STATUS'</span> <span style="color: #990099; font-weight: bold;">on</span> this slave.
                 Skip_Counter: <span style="color: #008080;">0</span>
          Exec_Master_Log_Pos: <span style="color: #008080;">4</span>
              Relay_Log_Space: <span style="color: #008080;">64337901</span>
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: <span style="color: #008080;">0</span>
           Master_SSL_Allowed: <span style="color: #990099; font-weight: bold;">No</span>
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: <span style="color: #9900FF; font-weight: bold;">NULL</span>
Master_SSL_Verify_Server_Cert: <span style="color: #990099; font-weight: bold;">No</span>
                Last_IO_Errno: <span style="color: #008080;">0</span>
                Last_IO_Error:
               Last_SQL_Errno: <span style="color: #008080;">1594</span>
               Last_SQL_Error: Relay <span style="color: #000099;">log</span> <span style="color: #990099; font-weight: bold;">read</span> failure: Could <span style="color: #CC0099; font-weight: bold;">not</span> parse relay <span style="color: #000099;">log</span> event entry. The possible reasons are: the master<span style="color: #008000;">'s binary log is corrupted (you can check this by running '</span>mysqlbinlog<span style="color: #008000;">' on the binary log), the slave'</span>s relay <span style="color: #000099;">log</span> <span style="color: #CC0099; font-weight: bold;">is</span> corrupted <span style="color: #FF00FF;">&#40;</span>you can <span style="color: #990099; font-weight: bold;">check</span> this by running <span style="color: #008000;">'mysqlbinlog'</span> <span style="color: #990099; font-weight: bold;">on</span> the relay <span style="color: #000099;">log</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> a network problem<span style="color: #000033;">,</span> <span style="color: #CC0099; font-weight: bold;">or</span> a bug <span style="color: #990099; font-weight: bold;">in</span> the master<span style="color: #008000;">'s or slave'</span>s MySQL code. <span style="color: #009900;">If</span> you want <span style="color: #990099; font-weight: bold;">to</span> <span style="color: #990099; font-weight: bold;">check</span> the master<span style="color: #008000;">'s binary log or slave'</span>s relay <span style="color: #000099;">log</span><span style="color: #000033;">,</span> you will be able <span style="color: #990099; font-weight: bold;">to</span> know their names by issuing <span style="color: #008000;">'SHOW SLAVE STATUS'</span> <span style="color: #990099; font-weight: bold;">on</span> this slave.
<span style="color: #008080;">1</span> row <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
 </pre></div></div>

<p>        从上面可以看到是中继日值或是Master上的日值出问题了。<br />
        首先如果是中继日值坏掉，那只需要找到同步的时间点，然后重新同步，这样就可以有新的中继日值了。如果Master上的日值坏了就麻烦了。<br />
从经验来看，这是中继日值出问题了。处理方法：</p>
<p>    需要找到同步的点。</p>
<p>日值为：Master_Log_File: mysql-bin.005121，Relay_Master_Log_File: mysql-bin.005121以Relay_Master_Log_File为准，Master_Log_File为参考。</p>
<p>日值执行时间点：</p>
<p>Exec_Master_Log_Pos: 4</p>
<p>那么现在就可以：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">  
      mysql<span style="color: #CC0099;">&gt;</span>stop slave<span style="color: #000033;">;</span>
&nbsp;
    mysql<span style="color: #CC0099;">&gt;</span>change master <span style="color: #990099; font-weight: bold;">to</span> Master_Log_File<span style="color: #CC0099;">=</span>’mysql<span style="color: #CC0099;">-</span><span style="color: #000099;">bin</span>.005121’<span style="color: #000033;">,</span> Master_Log_Pos<span style="color: #CC0099;">=</span><span style="color: #008080;">4</span><span style="color: #000033;">;</span>
   
    mysql<span style="color: #CC0099;">&gt;</span>start slave<span style="color: #000033;">;</span>
&nbsp;
    mysql<span style="color: #CC0099;">&gt;</span>show slave <span style="color: #990099; font-weight: bold;">status</span>\G<span style="color: #000033;">;</span></pre></div></div>

<p>    进行确认。</p>
<p> </p>
<p><strong>   </strong><strong>建议：</strong></p>
<p>    在使用MySQL-5.1.36以下的版本的同学，请尽快升级到MySQL-5.1.40 &amp; MySQL-5.1.37sp1</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/relay-log-read-failure/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>为什么mysql主从复制，从服务器的Time值诡异？</title>
		<link>http://www.mysqlsupport.cn/%e4%b8%ba%e4%bb%80%e4%b9%88mysql%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%ef%bc%8c%e4%bb%8e%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84time%e5%80%bc%e8%af%a1%e5%bc%82%ef%bc%9f/</link>
		<comments>http://www.mysqlsupport.cn/%e4%b8%ba%e4%bb%80%e4%b9%88mysql%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%ef%bc%8c%e4%bb%8e%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84time%e5%80%bc%e8%af%a1%e5%bc%82%ef%bc%9f/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 06:40:08 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p><strong>作者：吴炳锡　来源：<a href="http://www.mysqlsupport.cn//">http://www.mysqlsupport.cn/</a> 联系方式：select unhex('777562696E67786940676D61696C2E636F6D'); 载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong></p>]]></description>
			<content:encoded><![CDATA[<p><strong>作者：吴炳锡　来源：<a href="http://www.mysqlsupport.cn//">http://www.mysqlsupport.cn/</a> 联系方式：select unhex(&#8216;777562696E67786940676D61696C2E636F6D&#8217;); 载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong></p>
<p>    从服务器show slave status\G;状态正常，show processlist;这个时候我观察到一个复制线程的Time值为4294967295，这个数字为2^32-1,数据比较特殊，然后我再show processlist;Time成为0，再查看，Time值变为1，等会再查看的时候Time值又变为4294967295，反正TIME值就是在 4294967295,0,1之间变化，show slave status\G,从服务器正常在运作。<br />
mysql&gt; show processlist;<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| Id    | User        | Host      | db   | Command | Time       | State                                                                 | Info             |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
|     4 | system user |           | NULL | Connect |    2950273 | Waiting for master to send event                                      | NULL             |<br />
|     5 | system user |           | NULL | Connect | 4294967295 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |<br />
| 14814 | root        | localhost | NULL | Query   |          0 | NULL                                                                  | show processlist |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>mysql&gt; show processlist;<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| Id    | User        | Host      | db   | Command | Time    | State                                                                 | Info             |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
|     4 | system user |           | NULL | Connect | 2950543 | Waiting for master to send event                                      | NULL             |<br />
|     5 | system user |           | NULL | Connect |       0 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |<br />
| 14814 | root        | localhost | NULL | Query   |       0 | NULL                                                                  | show processlist |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>mysql&gt; show processlist;<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| Id    | User        | Host      | db   | Command | Time    | State                                                                 | Info             |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
|     4 | system user |           | NULL | Connect | 2950574 | Waiting for master to send event                                      | NULL             |<br />
|     5 | system user |           | NULL | Connect |       1 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |<br />
| 14814 | root        | localhost | NULL | Query   |       0 | NULL                                                                  | show processlist |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<div id="message10648028" class="t_msgfont">有两个原因：<br />
第一个： 这个情况我以前在4.X以前遇到过。后来升级到4.1后就没这个问题了。如果你的版本低于这个版本，有可能会这种情况。<br />
第二个：有可能是你的网络不稳定。导至从服务器连接Master不稳定，从而返还的时间比较不准确。或是你的Master太忙了，Slave得到的时间有可能超时了。</div>
<p>这个时间表示：<br />
Slave的SQL线程连接上Master的时间点和实际进行的SQL点的时间差别。例，当Slave和Master断开时间为30分钟，再时连上，这个时间为1800。<br />
另一方面网络不稳也会出现问题。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/%e4%b8%ba%e4%bb%80%e4%b9%88mysql%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%ef%bc%8c%e4%bb%8e%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84time%e5%80%bc%e8%af%a1%e5%bc%82%ef%bc%9f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>大表删除数据的思路</title>
		<link>http://www.mysqlsupport.cn/%e5%a4%a7%e8%a1%a8%e5%88%a0%e9%99%a4%e6%95%b0%e6%8d%ae%e7%9a%84%e6%80%9d%e8%b7%af/</link>
		<comments>http://www.mysqlsupport.cn/%e5%a4%a7%e8%a1%a8%e5%88%a0%e9%99%a4%e6%95%b0%e6%8d%ae%e7%9a%84%e6%80%9d%e8%b7%af/#comments</comments>
		<pubDate>Mon, 25 May 2009 09:40:45 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p><strong>作者：吴炳锡　来源：<a href="//">http://www.mysqlsupport.cn/</a> 联系方式：select unhex('777562696E67786940676D61696C2E636F6D'); 载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong></p>]]></description>
			<content:encoded><![CDATA[<p><strong>作者：吴炳锡　来源：<a href="//">http://www.mysqlsupport.cn/</a> 联系方式：select unhex(&#8216;777562696E67786940676D61696C2E636F6D&#8217;); 载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong></p>
<p>对于一个2000W的大表，一次走一个全表扫描确是很困难的。不过对于100W的表走一个全描扫也困难。</p>
<p>如果做这件事情又不想影响太大，就要分步来完成。</p>
<p>我给你一个思路你来参考一下。<br />
首先衡量删除操作有多大。<br />
selet count(*) from table1 a ,table2 b where a.pid=b.pid;<br />
如果都有索引的话，这个操作还是挺快的。<br />
如果操作的操作大于原表的40%，那么很有必要重建这个表了。</p>
<p>重建表的方法：就是按条件提取数据到一个新表，最后改名完成。这是一种方案。</p>
<p>另一种 删除方向。</p>
<p>上面通过比较觉的需要删除的量不是太大时，把需要删除的PID生到到另一个临时表中。<br />
mysql DBname -e &#8220;select a.pid from table1 a ,table2 b where a.pid=b.pid&#8221;&gt;del_pid.txt;</p>
<p>sed -i &#8216;1d&#8217; del_pid.txt<br />
awk &#8216;{print &#8220;delete from table1 where pid=&#8221;,$1,&#8221;;&#8221;}&#8217; del_pid.txt &gt;del_pid.sql<br />
mysql DBname&lt;del_pid.sql</p>
<p>这样把SQL拆成多个SQL执行速度应该不会太慢了。</p>
<p>如果还是感觉不行，那就只能分段操作了。</p>
<p> </p>
<p>备注：<a href="http://bbs3.chinaunix.net/thread-1453362-1-1.html">http://bbs3.chinaunix.net/thread-1453362-1-1.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/%e5%a4%a7%e8%a1%a8%e5%88%a0%e9%99%a4%e6%95%b0%e6%8d%ae%e7%9a%84%e6%80%9d%e8%b7%af/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql.user表怎么有两个root？密码怎么改？</title>
		<link>http://www.mysqlsupport.cn/mysql-user%e8%a1%a8%e6%80%8e%e4%b9%88%e6%9c%89%e4%b8%a4%e4%b8%aaroot%ef%bc%9f%e5%af%86%e7%a0%81%e6%80%8e%e4%b9%88%e6%94%b9%ef%bc%9f/</link>
		<comments>http://www.mysqlsupport.cn/mysql-user%e8%a1%a8%e6%80%8e%e4%b9%88%e6%9c%89%e4%b8%a4%e4%b8%aaroot%ef%bc%9f%e5%af%86%e7%a0%81%e6%80%8e%e4%b9%88%e6%94%b9%ef%bc%9f/#comments</comments>
		<pubDate>Thu, 14 May 2009 14:02:08 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>
		<category><![CDATA[MySQL基础]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p><strong>作者：吴炳锡　来源：<a href="//">http://www.mysqlsupport.cn/</a> 联系方式：select unhex('777562696E67786940676D61696C2E636F6D'); 载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong><br /> MySQL的用户名有两部分组成： 用户名＠机器名<br /> <br /> 用户名：一般用字母组成。<br /> 机器名：可以是机器ＩＰ也可以机器名。机器名可以用dns也可以在/etc/hosts中声明。</p>
<p>所以可以称为不是两个root用户。</p>
<p>反应到user表中,用户名对应user，机器名对应于host,密码对应于password<br />一个用户名完整的标识为：user@host <br /> <br /> 更改密码：<br /> set  password for '用户名'@'主机名‘=password('yourpassword');<br /> <br /> 所以你见到的两个Ｒｏｏｔ不能算是一个用户名的。</p>
<p> </p>]]></description>
			<content:encoded><![CDATA[<p><strong>作者：吴炳锡　来源：<a href="//">http://www.mysqlsupport.cn/</a> 联系方式：select unhex(&#8216;777562696E67786940676D61696C2E636F6D&#8217;); 载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong><br />
MySQL的用户名有两部分组成： 用户名＠机器名</p>
<p>用户名：一般用字母组成。<br />
机器名：可以是机器ＩＰ也可以机器名。机器名可以用dns也可以在/etc/hosts中声明。</p>
<p>所以可以称为不是两个root用户。</p>
<p>反应到user表中,用户名对应user，机器名对应于host,密码对应于password<br />
一个用户名完整的标识为：user@host</p>
<p>更改密码：<br />
set  password for &#8216;用户名&#8217;@'主机名‘=password(&#8216;yourpassword&#8217;);</p>
<p>所以你见到的两个Ｒｏｏｔ不能算是一个用户名的。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/mysql-user%e8%a1%a8%e6%80%8e%e4%b9%88%e6%9c%89%e4%b8%a4%e4%b8%aaroot%ef%bc%9f%e5%af%86%e7%a0%81%e6%80%8e%e4%b9%88%e6%94%b9%ef%bc%9f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>注意：MySQL用户密码中的“！”</title>
		<link>http://www.mysqlsupport.cn/%e6%b3%a8%e6%84%8f%ef%bc%9amysql%e7%94%a8%e6%88%b7%e5%af%86%e7%a0%81%e4%b8%ad%e7%9a%84%e2%80%9c%ef%bc%81%e2%80%9d/</link>
		<comments>http://www.mysqlsupport.cn/%e6%b3%a8%e6%84%8f%ef%bc%9amysql%e7%94%a8%e6%88%b7%e5%af%86%e7%a0%81%e4%b8%ad%e7%9a%84%e2%80%9c%ef%bc%81%e2%80%9d/#comments</comments>
		<pubDate>Wed, 06 May 2009 08:11:15 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>
		<category><![CDATA[MySQL基础]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<h3 class="post-title entry-title"></h3>
<div class="post-header-line-1"></div>
<div class="post-body entry-content"><strong>作者：吴炳锡　来源：<a href="http://www.mysqlsupport.cn/">http://www.mysqlsupport.cn/</a> 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong><br /><br /><strong>Tips</strong><br />　　禁止用户终端进入的一个方法。<br /><br />mysql&#62; <span style="color: #009900;">grant all privileges on wubx.* to </span><a href="mailto:"><span style="color: #009900;">'wubx'@'172.16.100.185'</span></a><span style="color: #009900;"> identified by 'fd52!wubx＆,';</span>]]></description>
			<content:encoded><![CDATA[<div class="post-body entry-content"><strong>作者：吴炳锡　来源：<a href="http://www.mysqlsupport.cn/">http://www.mysqlsupport.cn/</a> 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。</strong></div>
<p><strong>Tips</strong><br />
　　禁止用户终端进入的一个方法。</p>
<p>mysql&gt; <span style="color: #009900;">grant all privileges on wubx.* to </span><a href="mailto:"><span style="color: #009900;">&#8216;wubx&#8217;@'172.16.100.185&#8242;</span></a><span style="color: #009900;"> identified by &#8216;fd52!wubx＆,&#8217;;</span><br />
Query OK, 0 rows affected (0.00 sec)<br />
mysql&gt;<span style="color: #006600;">quit;</span><br />
<span style="color: #006600;">#mysql -h 172.16.100.185 -u wubx -pfd52!wubx＆,</span><br />
-bash: !wubx@,: event not found</p>
<p>仔细看一下，原来他把！后面的字符串做为命令执行了。又试了一个Navicat的管理端，也一样存在密码不正常的问题。<br />
在测一下程序方面是不是可以用，写一个ＰＨＰ测一下。<br />
<span style="color: #009900;"><!--p</sp--><br />
<span style="color: #009900;">$link = mysql_connect(&#8216;172.16.100.185&#8242;,&#8217;wubx&#8217;,'fd52!wubx＆,&#8217;);</span><br />
<span style="color: #009900;">if (!link){ </span><br />
<span style="color: #009900;">die(&#8216;Could not connect:&#8217;.mysql_error());</span><br />
<span style="color: #009900;">}</span><br />
<span style="color: #009900;">echo &#8216;Connected successfully&#8217;;mysql_close($link);</span><br />
<span style="color: #009900;">?&gt;<br />
</span>#<span style="color: #009900;">php testdb.php</span><br />
Connected successfully<br />
还看程序中能正常识别。<br />
PHP还是可以ＯＫ通过的。<br />
</span><span style="color: #009900;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/%e6%b3%a8%e6%84%8f%ef%bc%9amysql%e7%94%a8%e6%88%b7%e5%af%86%e7%a0%81%e4%b8%ad%e7%9a%84%e2%80%9c%ef%bc%81%e2%80%9d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>大量unauthenticated user出现</title>
		<link>http://www.mysqlsupport.cn/unauthenticated-user/</link>
		<comments>http://www.mysqlsupport.cn/unauthenticated-user/#comments</comments>
		<pubDate>Wed, 06 May 2009 08:08:13 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>
		<category><![CDATA[MySQL基础]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<h3 class="post-title entry-title"></h3>
<div class="post-header-line-1"></div>
<div class="post-body entry-content">作者：吴炳锡　来源：http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。<br /><br />首先查出来有那些ＩＰ连接mysql<br /><span style="color: #009900;">mysql -e "show processlist"&#124;awk '{print $3}'&#124;sed -e 's/:.*$//' &#124;sort &#124;uniq -c</span><br /><br />记录一下这些ＩＰ<br /><br />再收次一下那些ＩＰ出现　unauthenticated user<br /><span style="color: #009900;">mysql -e "show processlist"&#124;sed -s "/unauthenticated/"&#124;awk '{print $3}'&#124;sed -e 's/:.*$//' &#124;sort &#124;uniq -c</span><br /><br />多次执行，比较结果。]]></description>
			<content:encoded><![CDATA[<div class="post-body entry-content">作者：吴炳锡　来源：http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。</div>
<p>首先查出来有那些ＩＰ连接mysql<br />
<span style="color: #009900;">mysql -e &#8220;show processlist&#8221;|awk &#8216;{print $3}&#8217;|sed -e &#8217;s/:.*$//&#8217; |sort |uniq -c</span></p>
<p>记录一下这些ＩＰ</p>
<p>再收次一下那些ＩＰ出现　unauthenticated user<br />
<span style="color: #009900;">mysql -e &#8220;show processlist&#8221;|sed -s &#8220;/unauthenticated/&#8221;|awk &#8216;{print $3}&#8217;|sed -e &#8217;s/:.*$//&#8217; |sort |uniq -c</span></p>
<p>多次执行，比较结果。<br />
最终在/etc/hosts 里添加相应的ＩＰ及对应的名称。</p>
<p>参考建义(来自ＣＵ)：<br />
1、skip-name-resolve 已经添加之后； 最好在改用IP连接。<br />
2、max_allowed_packet 参数可以适当调整。<br />
3、MySQL 客户端库文件版本太低也有可能出现这个问题。<br />
4、如php、java等应用端服务压力大，线程异常中断也会导致连接MySQL异常断开。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/unauthenticated-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>unsiged 数值运算　记录</title>
		<link>http://www.mysqlsupport.cn/unsiged-operation/</link>
		<comments>http://www.mysqlsupport.cn/unsiged-operation/#comments</comments>
		<pubDate>Wed, 06 May 2009 08:06:31 +0000</pubDate>
		<dc:creator>wubx</dc:creator>
				<category><![CDATA[MySQL TIPS/FAQ]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<h3 class="post-title entry-title"></h3>
<div class="post-header-line-1"></div>
<div class="post-body entry-content">作者：吴炳锡　来源：http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。 <br />
<pre class="prettyprint"><br />mysql&#62; CREATE TABLE IF NOT EXISTS `ab`
<br />`id` int(11) NOT NULL,
<br />`id1` tinyint(3) unsigned DEFAULT NULL,
<br />`id2` tinyint(3) unsigned DEFAULT NULL
<br />) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
<br />Query OK, 0 rows affected (0.00 sec)
<br /></pre>
]]></description>
			<content:encoded><![CDATA[<h3 class="post-title entry-title"></h3>
<div class="post-header-line-1"></div>
<div class="post-body entry-content">作者：吴炳锡　来源：http://www.mysqlsupport.cn/ 联系方式： wubingxi#gmail.com 转载请注明作/译者和出处，并且不能用于商业用途，违者必究。 </p>
<pre class="prettyprint">mysql&gt; CREATE TABLE IF NOT EXISTS `ab`
`id` int(11) NOT NULL,
`id1` tinyint(3) unsigned DEFAULT NULL,
`id2` tinyint(3) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
Query OK, 0 rows affected (0.00 sec)
</pre>
<p><span style="color: #009900;">mysql&gt; insert into ab values(1,1,2);</span> <br /><span style="color: #009900;">Query OK, 1 row affected (0.00 sec)</span> </p>
<p><span style="color: #009900;">mysql&gt; select id1-id2 from ab;</span> <br /><span style="color: #009900;">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span> <br /><span style="color: #009900;">| id1-id2 |</span> <br /><span style="color: #009900;">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span> <br /><span style="color: #009900;">| 18446744073709551615 |</span> <br /><span style="color: #009900;">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span> <br /><span style="color: #009900;">1 row in set (0.00 sec)</span> </p>
<p><span style="font-weight: bold;">分析原因：</span> </p>
<div class="t_msgfont" id="message10452341">18446744073709551615 <br />这个值是bigint　unsigned 的最大值。 </p>
<p>MySQL内部的运算是按地址运算的。 </p>
<p>二进制减法运算的原理:减去一个正数相当于加上一个负数A－B=A+(－B)，对(－B)求补码，然后进行加法运算。　符号也进用相应的位表示了。 <br /><span style="font-weight: bold;">补码：补码或是反码的最高位为符号位，正数为０，负数为１ <br />　　　当二进制数为负数时，将原码的数值位逐位求反，然后在最低位加１得到补码。 <br />　　　当二进制数为正数时，其补码，反码与原码相。 </p>
<p>（补了一下二进制） <br /></span><br />
<meta equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<meta content="PowerPoint.Slide" name="ProgId" /><br />
<meta content="Microsoft PowerPoint 12" name="Generator" /><br />
<br />1-2 <br />过程：　0000 00001 &#8211; 0000 0010 = 0000 0001 +(-0000 0010) <br />#在这个求补码的过程中，按整数最大值来求了。用８个字节表示了。 <br />=0000 00001 + (11111111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1101 + 1 ) <br />=11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 </p>
<p>mysql&gt; select hex(18446744073709551615); <br />+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ <br />| hex(18446744073709551615) | <br />+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ <br />| FFFFFFFFFFFFFFFF | <br />+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ <br />1 row in set (0.00 sec) </p>
<p><span style="font-weight: bold;">参考：</span> <br /><a href="http://zhidao.baidu.com/question/36780022.html" target="_blank">http://zhidao.baidu.com/question/36780022.html</a> <br /><a href="http://www.mysqlsupport.cn/2009/04/mysql-4int-unsigned.html" target="_blank">http://www.mysqlsupport.cn/2009/04/mysql-4int-unsigned.html</a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.mysqlsupport.cn/unsiged-operation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
