<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!--这是一个由Feedsy提供技术支持的Feed，为了提高读者阅读的体验，以及满足用户美化自己Feed的需要，我们设计了多种精美的Feed模板，提供给大家选择，所有最终呈现出来的样式，皆由用户自愿选择使用，未经许可，任何团体和个人，请不要擅自修改样式或者盗用，这是对于用户选择权的尊重。--><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://www.feedsky.com/namespace/feed" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><fs:self_link href="http://feed.feedsky.com/sky000" type="application/rss+xml" /><lastBuildDate>Thu, 19 Apr 2012 02:18:06 GMT</lastBuildDate><title>Sky.Jian 朝阳的天空</title><description>MySQL &amp; Oracle DBA, 数据库性能优化，数据库架构设计</description><image><url>http://www.feedsky.com/feed/sky000/sc/gif</url><title>Sky.Jian 朝阳的天空</title><link>http://isky000.com</link></image><link>http://isky000.com</link><sy:updatePeriod>hourly</sy:updatePeriod><sy:updateFrequency>1</sy:updateFrequency><language>en</language><pubDate>Thu, 19 Apr 2012 02:18:06 GMT</pubDate><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/sky000" /><feedburner:info uri="sky000" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.0/</creativeCommons:license><item><title>MySQL数据库性能优化之存储引擎选择</title><link>http://feedproxy.google.com/~r/sky000/~3/la8TeZ8CPcY/mysql-performance-tuning-storage-engine</link><content:encoded><![CDATA[<p>接着上一篇 <strong><a href="http://isky000.com/database/mysql-performance-tuning-sql">MySQL 数据库性能优化之SQL优化</a></strong>，这是 <strong>MySQL数据库性能优化专题 </strong> 系列的第五篇文章：<strong><a href="http://isky000.com/database/mysql-performance-tuning-storage-engine">MySQL数据库性能优化之存储引擎选择</a></strong></p>
<p><em>离上一篇文章已经有很长时间没有更新这个MySQL数据库性能优化专题了，时间太紧加上人之惰性，今天这里将之前就规划好的关于存储引擎选择方面的内容更新出来，希望对大家有所帮助吧</em></p>
<p>MySQL 的存储引擎可能是所有关系型数据库产品中最具有特色的了，不仅可以同时使用多种存储引擎，而且每种存储引擎和MySQL之间使用插件方式这种非常松的耦合关系。</p>
<p>由于各存储引擎功能特性差异较大，这篇文章主要是介绍如何来选择合适的存储引擎来应对不同的业务场景。</p>
<ul>
<li>MyISAM
<ul>
<li>特性
<ol>
<li>不支持事务：MyISAM存储引擎不支持事务，所以对事务有要求的业务场景不能使用</li>
<li>表级锁定：其锁定机制是表级索引，这虽然可以让锁定的实现成本很小但是也同时大大降低了其并发性能</li>
<li>读写互相阻塞：不仅会在写入的时候阻塞读取，MyISAM还会在读取的时候阻塞写入，但读本身并不会阻塞另外的读</li>
<li>只会缓存索引：MyISAM可以通过key_buffer缓存以大大提高访问性能减少磁盘IO，但是这个缓存区只会缓存索引，而不会缓存数据</li>
</ol>
</li>
<li>适用场景
<ol>
<li>不需要事务支持（不支持）</li>
<li>并发相对较低（锁定机制问题）</li>
<li>数据修改相对较少（阻塞问题）</li>
<li>以读为主</li>
<li>数据一致性要求不是非常高</li>
</ol>
</li>
<li>最佳实践
<ol>
<li>尽量索引（缓存机制）</li>
<li>调整读写优先级，根据实际需求确保重要操作更优先</li>
<li>启用延迟插入改善大批量写入性能</li>
<li>尽量顺序操作让insert数据都写入到尾部，减少阻塞</li>
<li>分解大的操作，降低单个操作的阻塞时间</li>
<li>降低并发数，某些高并发场景通过应用来进行排队机制</li>
<li>对于相对静态的数据，充分利用Query Cache可以极大的提高访问效率</li>
<li>MyISAM的Count只有在全表扫描的时候特别高效，带有其他条件的count都需要进行实际的数据访问</li>
</ol>
</li>
</ul>
</li>
<li>InnoDB
<ul>
<li>特性
<ol>
<li>具有较好的事务支持：支持4个事务隔离级别，支持多版本读</li>
<li>行级锁定：通过索引实现，全表扫描仍然会是表锁，注意间隙锁的影响</li>
<li>读写阻塞与事务隔离级别相关</li>
<li>具有非常高效的缓存特性：能缓存索引，也能缓存数据</li>
<li>整个表和主键以Cluster方式存储，组成一颗平衡树</li>
<li>所有Secondary Index都会保存主键信息</li>
</ol>
</li>
<li>适用场景
<ol>
<li>需要事务支持（具有较好的事务特性）</li>
<li>行级锁定对高并发有很好的适应能力，但需要确保查询是通过索引完成</li>
<li>数据更新较为频繁的场景</li>
<li>数据一致性要求较高</li>
<li>硬件设备内存较大，可以利用InnoDB较好的缓存能力来提高内存利用率，尽可能减少磁盘 IO</li>
</ol>
</li>
<li>最佳实践
<ol>
<li>主键尽可能小，避免给Secondary index带来过大的空间负担</li>
<li>避免全表扫描，因为会使用表锁</li>
<li>尽可能缓存所有的索引和数据，提高响应速度</li>
<li>在大批量小插入的时候，尽量自己控制事务而不要使用autocommit自动提交</li>
<li>合理设置innodb_flush_log_at_trx_commit参数值，不要过度追求安全性</li>
<li>避免主键更新，因为这会带来大量的数据移动</li>
</ol>
</li>
</ul>
</li>
<li>NDBCluster
<ul>
<li>特性
<ol>
<li>分布式：分布式存储引擎，可以由多个NDBCluster存储引擎组成集群分别存放整体数据的一部分</li>
<li>支持事务：和Innodb一样，支持事务</li>
<li>可与mysqld不在一台主机：可以和mysqld分开存在于独立的主机上，然后通过网络和mysqld通信交互</li>
<li>内存需求量巨大：新版本索引以及被索引的数据必须存放在内存中，老版本所有数据和索引必须存在与内存中</li>
</ol>
</li>
<li>适用场景
<ol>
<li>具有非常高的并发需求</li>
<li>对单个请求的响应并不是非常的critical</li>
<li>查询简单，过滤条件较为固定，每次请求数据量较少，又不希望自己进行水平Sharding</li>
</ol>
</li>
<li>最佳实践
<ol>
<li>尽可能让查询简单，避免数据的跨节点传输</li>
<li>尽可能满足SQL节点的计算性能，大一点的集群SQL节点会明显多余Data节点</li>
<li>在各节点之间尽可能使用万兆网络环境互联，以减少数据在网络层传输过程中的延时</li>
</ol>
</li>
</ul>
</li>
</ul>
<p>注：以上三个存储引擎是目前相对主流的存储引擎，还有其他类似如：Memory，Merge，CSV，Archive等存储引擎的使用场景都相对较少，这里就不一一分析了，如果有朋友感兴趣，后面再补充吧。</p>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/mysql-performance-tuning-storage-engine">http://isky000.com/database/mysql-performance-tuning-storage-engine</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">2012DTCC – 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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL 数据库性能优化之SQL优化</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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine">
                        <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?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-book-preview&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine">
                        <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" 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><img src="http://www1.feedsky.com/t1/629342026/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-performance-tuning-storage-engine" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/ScQsLuzRsuxxGekEQJvcHvGhlqY/0/da"><img src="http://feedads.g.doubleclick.net/~a/ScQsLuzRsuxxGekEQJvcHvGhlqY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ScQsLuzRsuxxGekEQJvcHvGhlqY/1/da"><img src="http://feedads.g.doubleclick.net/~a/ScQsLuzRsuxxGekEQJvcHvGhlqY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/la8TeZ8CPcY" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/mysql-performance-tuning-storage-engine/feed</wfw:commentRss><slash:comments>0</slash:comments><description>接着上一篇 MySQL 数据库性能优化之SQL优化，这是 MySQL数据库性能优化专题  系列的第五篇文章：MySQL数据库性能优化之存储引擎选择
离上一篇文章已经有很长时间没有更新这个MySQL数据库性能优化专题了，时间太紧加上人之惰性，今天这里将之前就规划好的关于存储引擎选择方面的内容更新出来，希望对大家有所帮助吧
MySQL 的存储引擎可能是所有关系型数据库产品中最具有特色的了，不仅可以同时使用多种存储引擎，而且每种存储引擎和MySQL之间使用插件方式这种非常松的耦合关系。
由于各存储引擎功能特性差异较大，这篇文章主要是介绍如何来选择合适的存储引擎来应对不同的业务场景。

MyISAM

特性

不支持事务：MyISAM存储引擎不支持事务，所以对事务有要求的业务场景不能使用
表级锁定：其锁定机制是表级索引，这虽然可以让锁定的实现成本很小但是也同时大大降低了其并发性能
读写互相阻塞：不仅会在写入的时候阻塞读取，MyISAM还会在读取的时候阻塞写入，但读本身并不会阻塞另外的读
只会缓存索引：MyISAM可以通过key_buffer缓存以大大提高访问性能减少磁盘IO，但是这个缓存区只会缓存索引，而不会缓存数据


适用场景

不需要事务支持（不支持）
并发相对较低（锁定机制问题）
数据修改相对较少（阻塞问题）
以读为主
数据一致性要求不是非常高


最佳实践

尽量索引（缓存机制）
调整读写优先级，根据实际需求确保重要操作更优先
启用延迟插入改善大批量写入性能
尽量顺序操作让insert数据都写入到尾部，减少阻塞
分解大的操作，降低单个操作的阻塞时间
降低并发数，某些高并发场景通过应用来进行排队机制
对于相对静态的数据，充分利用Query Cache可以极大的提高访问效率
MyISAM的Count只有在全表扫描的时候特别高效，带有其他条件的count都需要进行实际的数据访问




InnoDB

特性

具有较好的事务支持：支持4个事务隔离级别，支持多版本读
行级锁定：通过索引实现，全表扫描仍然会是表锁，注意间隙锁的影响
读写阻塞与事务隔离级别相关
具有非常高效的缓存特性：能缓存索引，也能缓存数据
整个表和主键以Cluster方式存储，组成一颗平衡树
所有Secondary Index都会保存主键信息


适用场景

需要事务支持（具有较好的事务特性）
行级锁定对高并发有很好的适应能力，但需要确保查询是通过索引完成
数据更新较为频繁的场景
数据一致性要求较高
硬件设备内存较大，可以利用InnoDB较好的缓存能力来提高内存利用率，尽可能减少磁盘 IO


最佳实践

主键尽可能小，避免给Secondary index带来过大的空间负担
避免全表扫描，因为会使用表锁
尽可能缓存所有的索引和数据，提高响应速度
在大批量小插入的时候，尽量自己控制事务而不要使用autocommit自动提交
合理设置innodb_flush_log_at_trx_commit参数值，不要过度追求安全性
避免主键更新，因为这会带来大量的数据移动




NDBCluster

特性

分布式：分布式存储引擎，可以由多个NDBCluster存储引擎组成集群分别存放整体数据的一部分
支持事务：和Innodb一样，支持事务
可与mysqld不在一台主机：可以和mysqld分开存在于独立的主机上，然后通过网络和mysqld通信交互
内存需求量巨大：新版本索引以及被索引的数据必须存放在内存中，老版本所有数据和索引必须存在与内存中


适用场景

具有非常高的并发需求
对单个请求的响应并不是非常的critical
查询简单，过滤条件较为固定，每次请求数据量较少，又不希望自己进行水平Sharding


最佳实践

尽可能让查询简单，避免数据的跨节点传输
尽可能满足SQL节点的计算性能，大一点的集群SQL节点会明显多余Data节点
在各节点之间尽可能使用万兆网络环境互联，以减少数据在网络层传输过程中的延时





注：以上三个存储引擎是目前相对主流的存储引擎，还有其他类似如：Memory，Merge，CSV，Archive等存储引擎的使用场景都相对较少，这里就不一一分析了，如果有朋友感兴趣，后面再补充吧。
作者： Sky.Jian &amp;#160;发布在：iSky000.com &amp;#160;欢迎&amp;#160;订阅本站FeedCopyright &amp;#169; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 版权声明 链接：http://isky000.com/database/mysql-performance-tuning-storage-engineHosted On Dreamhost,折扣码 iMySQLer )&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之SQL优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之索引优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-book-preview&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;《MySQL性能调优与架构设计》即将上架&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/629342026/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-performance-tuning-storage-engine" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>storage engine</category><category>MySQL数据库性能优化专题</category><category>MySQL</category><category>DataBase</category><category>performance tuning</category><pubDate>Thu, 19 Apr 2012 10:18:06 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/mysql-performance-tuning-storage-engine#comments</comments><guid isPermaLink="false">http://isky000.com/?p=1007</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/mysql-performance-tuning-storage-engine</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/629342026/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/mysql-performance-tuning-storage-engine</feedburner:origLink></item><item><title>2012DTCC – MySQL性能调优最佳实践</title><link>http://feedproxy.google.com/~r/sky000/~3/I9N9g_Lbn4U/2012dtcc-mysql-performance-tuning-practise</link><content:encoded><![CDATA[<p>上周受邀于 IT168，在 2012年度的 DTCC 大会上做了一个小的主题分享，内容主要是最近几年在 MySQL 数据库的性能调优过程中积累的一点点经验总结，希望能对大家有用。</p>
<p>其中部分内容在之前的 <a href="http://blog.thinkinlamp.com/2011/">第二届华东地区数据库大会</a> 上已经有过分享，这次是在当时分享内容的基础上增加了硬件和系统层面的内容，同时根据听众反馈对原有内容进行了部分优化改进。</p>
<p>以下就是这次分享的 PPT 内容（有更新）：</p>
<div style="width:595px" id="__ss_12552321"> <strong style="display:block;margin:12px 0 5px"><a href="http://www.slideshare.net/sky000/mysql-12552321" title="MySQL性能调优最佳实践" target="_blank">MySQL性能调优最佳实践</a></strong> <object id="__sse12552321" width="595" height="497"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysql-120415213911-phpapp01&#038;stripped_title=mysql-12552321&#038;userName=sky000" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"/><embed name="__sse12552321" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysql-120415213911-phpapp01&#038;stripped_title=mysql-12552321&#038;userName=sky000" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="595" height="497"></embed></object>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/sky000" target="_blank">Sky Jian</a> </div>
</p></div>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise">http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL 数据库性能优化之SQL优化</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?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-book-preview&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise">
                        <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" 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><img src="http://www1.feedsky.com/t1/628286866/sky000/feedsky/s.gif?r=http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/YeNrG9_5sCNuhsGFj2DeVeFiuQ4/0/da"><img src="http://feedads.g.doubleclick.net/~a/YeNrG9_5sCNuhsGFj2DeVeFiuQ4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YeNrG9_5sCNuhsGFj2DeVeFiuQ4/1/da"><img src="http://feedads.g.doubleclick.net/~a/YeNrG9_5sCNuhsGFj2DeVeFiuQ4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/I9N9g_Lbn4U" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise/feed</wfw:commentRss><slash:comments>5</slash:comments><description>上周受邀于 IT168，在 2012年度的 DTCC 大会上做了一个小的主题分享，内容主要是最近几年在 MySQL 数据库的性能调优过程中积累的一点点经验总结，希望能对大家有用。
其中部分内容在之前的 第二届华东地区数据库大会 上已经有过分享，这次是在当时分享内容的基础上增加了硬件和系统层面的内容，同时根据听众反馈对原有内容进行了部分优化改进。
以下就是这次分享的 PPT 内容（有更新）：
 MySQL性能调优最佳实践 
 View more presentations from Sky Jian 

作者： Sky.Jian &amp;#160;发布在：iSky000.com &amp;#160;欢迎&amp;#160;订阅本站FeedCopyright &amp;#169; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 版权声明 链接：http://isky000.com/database/2012dtcc-mysql-performance-tuning-practiseHosted On Dreamhost,折扣码 iMySQLer )&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之索引优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之SQL优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-book-preview&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;《MySQL性能调优与架构设计》即将上架&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286866/sky000/feedsky/s.gif?r=http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>MySQL</category><category>2012dtcc</category><category>DataBase</category><category>performance tuning</category><pubDate>Mon, 16 Apr 2012 10:43:29 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise#comments</comments><guid isPermaLink="false">http://isky000.com/?p=1034</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286866/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise</feedburner:origLink></item><item><title>昨日网摘 [2012-04-16]:sky000 @ del.icio.us</title><link>http://feedproxy.google.com/~r/sky000/~3/uh_fahkVJ-Q/sky000</link><guid isPermaLink="false">http://www.delicious.com/sky000#2012-04-16</guid><pubDate>Mon, 16 Apr 2012 00:00:00 +0800</pubDate><description>&lt;ul&gt;&lt;li&gt;&lt;a href='http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise/comment-page-1#comment-11033' title='link to ..'&gt;» 2012DTCC – MySQL性能调优最佳实践 - Sky.Jian – i Sky000 - 简朝阳?log=out&lt;/a&gt;&lt;br/&gt;&lt;div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bXoPhLfjpVroCYQXrlaPkbImdAM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bXoPhLfjpVroCYQXrlaPkbImdAM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bXoPhLfjpVroCYQXrlaPkbImdAM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bXoPhLfjpVroCYQXrlaPkbImdAM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/sky000/~4/uh_fahkVJ-Q" height="1" width="1"/&gt;</description><fs:burntype>mark day</fs:burntype><fs:srclink>http://isky000.com/database/2012dtcc-mysql-performance-tuning-practise/comment-page-1#comment-11033</fs:srclink><fs:srcfeed>http://del.icio.us/rss/sky000</fs:srcfeed><fs:itemid>feedsky/sky000/~1220317/628546916/1222002</fs:itemid><feedburner:origLink>http://www.delicious.com/sky000#2012-04-16</feedburner:origLink></item><item><title>第二届华东地区数据库大会的PPT</title><link>http://feedproxy.google.com/~r/sky000/~3/ZrEYqueOM8k/2nd-east-china-database-conference</link><content:encoded><![CDATA[<p>这个月11号应 <a href="http://weibo.com/rory" target="_blank">蝎子</a> 同学和 <a href="http://www.thinkinlamp.com">ThinkInLamp</a> 的邀请，在上海光大会展中心参加了由 ThinkInLamp 社区组织的 <a href="http://blog.thinkinlamp.com/2011/">第二届华东地区数据库大会</a>，并做了一个题为“浅谈MySQL数据库优化”的主题分享交流。</p>
<p>考虑到参会人员大多是一线的技术工程师，而且还有很多是开发人员，所以内容更偏重于一些指导性的原则，会后将 PPT 格式稍作了调整，这里再发出来希望对感兴趣的朋友有所帮助。</p>
<div style="width:595px" id="__ss_10556115"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/sky000/mysql-10556115" title="浅谈 MySQL 性能调优" target="_blank">浅谈 MySQL 性能调优</a></strong> <object id="__sse10556115" width="595" height="497"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysql-111212010228-phpapp02&#038;stripped_title=mysql-10556115&#038;userName=sky000" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"/><embed name="__sse10556115" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysql-111212010228-phpapp02&#038;stripped_title=mysql-10556115&#038;userName=sky000" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="595" height="497"></embed></object>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/sky000" target="_blank">Sky Jian</a> </div>
</p></div>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/2nd-east-china-database-conference">http://isky000.com/database/2nd-east-china-database-conference</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">2012DTCC – 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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL 数据库性能优化之SQL优化</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" 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><img src="http://www1.feedsky.com/t1/628286867/sky000/feedsky/s.gif?r=http://isky000.com/database/2nd-east-china-database-conference" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/1tVPMqn8ZKHiE0PPQ_8ac0KH2ds/0/da"><img src="http://feedads.g.doubleclick.net/~a/1tVPMqn8ZKHiE0PPQ_8ac0KH2ds/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/1tVPMqn8ZKHiE0PPQ_8ac0KH2ds/1/da"><img src="http://feedads.g.doubleclick.net/~a/1tVPMqn8ZKHiE0PPQ_8ac0KH2ds/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/ZrEYqueOM8k" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/2nd-east-china-database-conference/feed</wfw:commentRss><slash:comments>7</slash:comments><description>这个月11号应 蝎子 同学和 ThinkInLamp 的邀请，在上海光大会展中心参加了由 ThinkInLamp 社区组织的 第二届华东地区数据库大会，并做了一个题为“浅谈MySQL数据库优化”的主题分享交流。
考虑到参会人员大多是一线的技术工程师，而且还有很多是开发人员，所以内容更偏重于一些指导性的原则，会后将 PPT 格式稍作了调整，这里再发出来希望对感兴趣的朋友有所帮助。
 浅谈 MySQL 性能调优 
 View more presentations from Sky Jian 

作者： Sky.Jian &amp;#160;发布在：iSky000.com &amp;#160;欢迎&amp;#160;订阅本站FeedCopyright &amp;#169; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 版权声明 链接：http://isky000.com/database/2nd-east-china-database-conferenceHosted On Dreamhost,折扣码 iMySQLer )&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之索引优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2F2nd-east-china-database-conference"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之SQL优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286867/sky000/feedsky/s.gif?r=http://isky000.com/database/2nd-east-china-database-conference" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>MySQL</category><category>DataBase</category><category>performance tuning</category><pubDate>Thu, 22 Dec 2011 09:27:12 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/2nd-east-china-database-conference#comments</comments><guid isPermaLink="false">http://isky000.com/?p=1029</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/2nd-east-china-database-conference</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286867/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/2nd-east-china-database-conference</feedburner:origLink></item><item><title>MySQL 数据库性能优化之SQL优化</title><link>http://feedproxy.google.com/~r/sky000/~3/oz7MedM1dtw/mysql-performance-tuning-sql</link><content:encoded><![CDATA[<p>接着上一篇 <a href="http://isky000.com/database/mysql-performance-tuning-index">MySQL 数据库性能优化之索引优化</a>，这是 <strong>MySQL数据库性能优化专题 </strong>系列的第四篇文章：<strong><a href="http://isky000.com/database/mysql-performance-tuning-sql">MySQL 数据库性能优化之SQL优化</a></strong></p>
<p>有人反馈之前几篇文章过于理论缺少实际操作细节，这篇文章就多一些可操作性的内容吧。</p>
<p><em>注：这篇文章是以 MySQL 为背景，很多内容同时适用于其他关系型数据库，需要有一些索引知识为基础</em></p>
<ul>
<li><strong>优化目标 </strong>
<ol>
<li>减少 IO 次数<br />
IO永远是数据库最容易瓶颈的地方，这是由数据库的职责所决定的，大部分数据库操作中超过90%的时间都是 IO 操作所占用的，减少 IO 次数是 SQL 优化中需要第一优先考虑，当然，也是收效最明显的优化手段。</li>
<li>降低 CPU 计算<br />
除了 IO 瓶颈之外，SQL优化中需要考虑的就是 CPU 运算量的优化了。order by, group by,distinct &#8230; 都是消耗 CPU 的大户（这些操作基本上都是 CPU 处理内存中的数据比较运算）。当我们的 IO 优化做到一定阶段之后，降低 CPU 计算也就成为了我们 SQL 优化的重要目标</li>
</ol>
</li>
<li><strong>优化方法 </strong>
<ol>
<li>改变 SQL 执行计划<br />
明确了优化目标之后，我们需要确定达到我们目标的方法。对于 SQL 语句来说，达到上述2个目标的方法其实只有一个，那就是改变 SQL 的执行计划，让他尽量“少走弯路”，尽量通过各种“捷径”来找到我们需要的数据，以达到 “减少 IO 次数” 和 “降低 CPU 计算” 的目标</li>
</ol>
</li>
<li><strong>常见误区 </strong>
<ol>
<li>count(1)和count(primary_key) 优于 count(*)<br />
很多人为了统计记录条数，就使用 count(1) 和 count(primary_key) 而不是 count(*) ，他们认为这样性能更好，其实这是一个误区。对于有些场景，这样做可能性能会更差，应为数据库对 count(*) 计数操作做了一些特别的优化。</li>
<li>count(column) 和 count(*) 是一样的<br />
这个误区甚至在很多的资深工程师或者是 DBA 中都普遍存在，很多人都会认为这是理所当然的。实际上，count(column) 和 count(*) 是一个完全不一样的操作，所代表的意义也完全不一样。<br />
count(column) 是表示结果集中有多少个column字段不为空的记录<br />
count(*) 是表示整个结果集有多少条记录</li>
<li>select a,b from &#8230; 比 select a,b,c from &#8230; 可以让数据库访问更少的数据量<br />
这个误区主要存在于大量的开发人员中，主要原因是对数据库的存储原理不是太了解。<br />
实际上，大多数关系型数据库都是按照行（row）的方式存储，而数据存取操作都是以一个固定大小的IO单元（被称作 block 或者 page）为单位，一般为4KB，8KB&#8230; 大多数时候，每个IO单元中存储了多行，每行都是存储了该行的所有字段（lob等特殊类型字段除外）。<br />
所以，我们是取一个字段还是多个字段，实际上数据库在表中需要访问的数据量其实是一样的。<br />
当然，也有例外情况，那就是我们的这个查询在索引中就可以完成，也就是说当只取 a,b两个字段的时候，不需要回表，而c这个字段不在使用的索引中，需要回表取得其数据。在这样的情况下，二者的IO量会有较大差异。</li>
<li>order by 一定需要排序操作<br />
我们知道索引数据实际上是有序的，如果我们的需要的数据和某个索引的顺序一致，而且我们的查询又通过这个索引来执行，那么数据库一般会省略排序操作，而直接将数据返回，因为数据库知道数据已经满足我们的排序需求了。<br />
实际上，利用索引来优化有排序需求的 SQL，是一个非常重要的优化手段<br />
延伸阅读：<a href="http://isky000.com/database/mysql_order_by_implement">MySQL ORDER BY 的实现分析</a> ，<a href="http://isky000.com/database/mysql_group_by_implement">MySQL 中 GROUP BY 基本实现原理</a> 以及 <a href="http://isky000.com/database/mysql_distinct_implement">MySQL DISTINCT 的基本实现原理</a> 这3篇文章中有更为深入的分析，尤其是第一篇</li>
<li>执行计划中有 filesort 就会进行磁盘文件排序<br />
有这个误区其实并不能怪我们，而是因为 MySQL 开发者在用词方面的问题。filesort 是我们在使用 explain 命令查看一条 SQL 的执行计划的时候可能会看到在 “Extra” 一列显示的信息。<br />
实际上，只要一条 SQL 语句需要进行排序操作，都会显示“Using filesort”，这并不表示就会有文件排序操作。<br />
延伸阅读：理解 <a href="http://isky000.com/database/do-you-really-understand-filesort">MySQL Explain 命令输出中的filesort</a>，我在这里有更为详细的介绍</li>
</ol>
</li>
<li><strong>基本原则 </strong>
<ol>
<li>尽量少 join<br />
MySQL 的优势在于简单，但这在某些方面其实也是其劣势。MySQL 优化器效率高，但是由于其统计信息的量有限，优化器工作过程出现偏差的可能性也就更多。对于复杂的多表 Join，一方面由于其优化器受限，再者在 Join 这方面所下的功夫还不够，所以性能表现离 Oracle 等关系型数据库前辈还是有一定距离。但如果是简单的单表查询，这一差距就会极小甚至在有些场景下要优于这些数据库前辈。</li>
<li>尽量少排序<br />
排序操作会消耗较多的 CPU 资源，所以减少排序可以在缓存命中率高等 IO 能力足够的场景下会较大影响 SQL 的响应时间。<br />
对于MySQL来说，减少排序有多种办法，比如：</p>
<ul>
<li>上面误区中提到的通过利用索引来排序的方式进行优化</li>
<li>减少参与排序的记录条数</li>
<li>非必要不对数据进行排序</li>
<li>&#8230;</li>
</ul>
</li>
<li>尽量避免 select *<br />
很多人看到这一点后觉得比较难理解，上面不是在误区中刚刚说 select 子句中字段的多少并不会影响到读取的数据吗？<br />
是的，大多数时候并不会影响到 IO 量，但是当我们还存在 order by 操作的时候，select 子句中的字段多少会在很大程度上影响到我们的排序效率，这一点可以通过我之前一篇介绍 <a href="http://isky000.com/database/mysql_order_by_implement">MySQL ORDER BY 的实现分析</a> 的文章中有较为详细的介绍。<br />
此外，上面误区中不是也说了，只是大多数时候是不会影响到 IO 量，当我们的查询结果仅仅只需要在索引中就能找到的时候，还是会极大减少 IO 量的。</li>
<li>尽量用 join 代替子查询<br />
虽然 Join 性能并不佳，但是和 MySQL 的子查询比起来还是有非常大的性能优势。MySQL 的子查询执行计划一直存在较大的问题，虽然这个问题已经存在多年，但是到目前已经发布的所有稳定版本中都普遍存在，一直没有太大改善。虽然官方也在很早就承认这一问题，并且承诺尽快解决，但是至少到目前为止我们还没有看到哪一个版本较好的解决了这一问题。</li>
<li>尽量少 or<br />
当 where 子句中存在多个条件以“或”并存的时候，MySQL 的优化器并没有很好的解决其执行计划优化问题，再加上 MySQL 特有的 SQL 与 Storage 分层架构方式，造成了其性能比较低下，很多时候使用 union all 或者是union（必要的时候）的方式来代替“or”会得到更好的效果。</li>
<li>尽量用 union all 代替 union<br />
union 和 union all 的差异主要是前者需要将两个（或者多个）结果集合并后再进行唯一性过滤操作，这就会涉及到排序，增加大量的 CPU 运算，加大资源消耗及延迟。所以当我们可以确认不可能出现重复结果集或者不在乎重复结果集的时候，尽量使用 union all 而不是 union。</li>
<li>尽量早过滤<br />
这一优化策略其实最常见于索引的优化设计中（将过滤性更好的字段放得更靠前）。<br />
在 SQL 编写中同样可以使用这一原则来优化一些 Join 的 SQL。比如我们在多个表进行分页数据查询的时候，我们最好是能够在一个表上先过滤好数据分好页，然后再用分好页的结果集与另外的表 Join，这样可以尽可能多的减少不必要的 IO 操作，大大节省 IO 操作所消耗的时间。</li>
<li>避免类型转换<br />
这里所说的“类型转换”是指 where 子句中出现 column 字段的类型和传入的参数类型不一致的时候发生的类型转换：</p>
<ul>
<li>人为在column_name 上通过转换函数进行转换<br />
直接导致 MySQL（实际上其他数据库也会有同样的问题）无法使用索引，如果非要转换，应该在传入的参数上进行转换</li>
<li>由数据库自己进行转换<br />
如果我们传入的数据类型和字段类型不一致，同时我们又没有做任何类型转换处理，MySQL 可能会自己对我们的数据进行类型转换操作，也可能不进行处理而交由存储引擎去处理，这样一来，就会出现索引无法使用的情况而造成执行计划问题。</li>
</ul>
</li>
<li>优先优化高并发的 SQL，而不是执行频率低某些“大”SQL<br />
对于破坏性来说，高并发的 SQL 总是会比低频率的来得大，因为高并发的 SQL 一旦出现问题，甚至不会给我们任何喘息的机会就会将系统压跨。而对于一些虽然需要消耗大量 IO 而且响应很慢的 SQL，由于频率低，即使遇到，最多就是让整个系统响应慢一点，但至少可能撑一会儿，让我们有缓冲的机会。</li>
<li>从全局出发优化，而不是片面调整<br />
SQL 优化不能是单独针对某一个进行，而应充分考虑系统中所有的 SQL，尤其是在通过调整索引优化 SQL 的执行计划的时候，千万不能顾此失彼，因小失大。</li>
<li>尽可能对每一条运行在数据库中的SQL进行 explain<br />
优化 SQL，需要做到心中有数，知道 SQL 的执行计划才能判断是否有优化余地，才能判断是否存在执行计划问题。在对数据库中运行的 SQL 进行了一段时间的优化之后，很明显的问题 SQL 可能已经很少了，大多都需要去发掘，这时候就需要进行大量的 explain 操作收集执行计划，并判断是否需要进行优化。</li>
</ol>
</li>
</ul>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/mysql-performance-tuning-sql">http://isky000.com/database/mysql-performance-tuning-sql</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">2012DTCC – 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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql">
                        <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?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-performanc-architecture-cover1&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql">
                        <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" 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><img src="http://www1.feedsky.com/t1/628286868/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-performance-tuning-sql" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/QQ4CkYyFdOHd4An0sNS3a7nfP_I/0/da"><img src="http://feedads.g.doubleclick.net/~a/QQ4CkYyFdOHd4An0sNS3a7nfP_I/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/QQ4CkYyFdOHd4An0sNS3a7nfP_I/1/da"><img src="http://feedads.g.doubleclick.net/~a/QQ4CkYyFdOHd4An0sNS3a7nfP_I/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/oz7MedM1dtw" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/mysql-performance-tuning-sql/feed</wfw:commentRss><slash:comments>12</slash:comments><description>接着上一篇 MySQL 数据库性能优化之索引优化，这是 MySQL数据库性能优化专题 系列的第四篇文章：MySQL 数据库性能优化之SQL优化
有人反馈之前几篇文章过于理论缺少实际操作细节，这篇文章就多一些可操作性的内容吧。
注：这篇文章是以 MySQL 为背景，很多内容同时适用于其他关系型数据库，需要有一些索引知识为基础

优化目标 

减少 IO 次数
IO永远是数据库最容易瓶颈的地方，这是由数据库的职责所决定的，大部分数据库操作中超过90%的时间都是 IO 操作所占用的，减少 IO 次数是 SQL 优化中需要第一优先考虑，当然，也是收效最明显的优化手段。
降低 CPU 计算
除了 IO 瓶颈之外，SQL优化中需要考虑的就是 CPU 运算量的优化了。order by, group by,distinct &amp;#8230; 都是消耗 CPU 的大户（这些操作基本上都是 CPU 处理内存中的数据比较运算）。当我们的 IO 优化做到一定阶段之后，降低 CPU 计算也就成为了我们 SQL 优化的重要目标


优化方法 

改变 SQL 执行计划
明确了优化目标之后，我们需要确定达到我们目标的方法。对于 SQL 语句来说，达到上述2个目标的方法其实只有一个，那就是改变 SQL 的执行计划，让他尽量“少走弯路”，尽量通过各种“捷径”来找到我们需要的数据，以达到 “减少 IO 次数” 和 “降低 CPU 计算” 的目标


常见误区 

count(1)和count(primary_key) 优于 [...]&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之索引优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-performanc-architecture-cover1&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;《MySQL性能调优与架构设计》封面初稿&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286868/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-performance-tuning-sql" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>MySQL数据库性能优化专题</category><category>MySQL</category><category>DataBase</category><category>performance tuning</category><pubDate>Mon, 28 Nov 2011 15:21:30 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/mysql-performance-tuning-sql#comments</comments><guid isPermaLink="false">http://isky000.com/?p=1005</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/mysql-performance-tuning-sql</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286868/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/mysql-performance-tuning-sql</feedburner:origLink></item><item><title>MySQL 数据库性能优化之索引优化</title><link>http://feedproxy.google.com/~r/sky000/~3/zsgvlpXpGko/mysql-performance-tuning-index</link><content:encoded><![CDATA[<p>接着上一篇 <a href="http://isky000.com/database/mysql-perfornamce-tuning-schema">MySQL 数据库性能优化之表结构</a>，这是 <strong>MySQL数据库性能优化专题 </strong>系列的第三篇文章：<strong><a href="http://isky000.com/database/mysql-performance-tuning-index">MySQL 数据库性能优化之索引优化</a></strong></p>
<p>大家都知道索引对于数据访问的性能有非常关键的作用，都知道索引可以提高数据访问效率。</p>
<p>为什么索引能提高数据访问性能？他会不会有“副作用”？是不是索引创建越多，性能就越好？到底该如何设计索引，才能最大限度的发挥其效能？</p>
<p>这篇文章主要是带着上面这几个问题来做一个简要的分析，同时排除了业务场景所带来的特殊性，请不要纠结业务场景的影响。</p>
<ul>
<li><strong>索引为什么能提高数据访问性能？</strong><br />
很多人只知道索引能够提高数据库的性能，但并不是特别了解其原理，其实我们可以用一个生活中的示例来理解。</p>
<p>我们让一位不太懂计算机的朋友去图书馆确认一本叫做《MySQL性能调优与架构设计》的书是否在藏，这样对他说：“请帮我借一本计算机类的数据库书籍，是属于 MySQL 数据库范畴的，叫做《MySQL性能调优与架构设计》”。朋友会根据所属类别，前往存放“计算机”书籍区域的书架，然后再寻找“数据库”类存放位置，再找到一堆讲述“MySQL”的书籍，最后可能发现目标在藏（也可能已经借出不在书架上）。</p>
<p>在这个过程中： “计算机”-&gt;“数据库”-&gt;“MySQL”-&gt;“在藏”-&gt;《MySQL性能调优与架构设计》其实就是一个“根据索引查找数据”的典型案例，“计算机”-&gt;“数据库”-&gt;“MySQL”-&gt;“在藏” 就是朋友查找书籍的索引。</p>
<p>假设没有这个索引，那查找这本书的过程会变成怎样呢？朋友只能从图书馆入口一个书架一个书架的“遍历”，直到找到《MySQL性能调优与架构设计》这本书为止。如果幸运，可能在第一个书架就找到。但如果不幸呢，那就惨了，可能要将整个图书馆所有的书架都找一遍才能找到我们想要的这本书。</p>
<p>注：这个例子中的“索引”是记录在朋友大脑中的，实际上，每个图书馆都会有一个非常全的实际存在的索引系统（大多位于入口显眼处），由很多个贴上了明显标签的小抽屉构成。这个索引系统中存放这非常齐全详尽的索引数据，标识出我们需要查找的“目标”在某个区域的某个书架上。而且每当有新的书籍入库，旧的书籍销毁以及书记信息修改，都需要对索引系统进行及时的修正。</p>
</li>
</ul>
<p>下面我们通过上面这个生活中的小示例，来分析一下索引，看看能的出哪些结论？</p>
<ul>
<li><strong>索引有哪些“副作用”？ </strong>
<ol>
<li>图书的变更（增，删，改）都需要修订索引，索引存在<em><span style="color: #0000ff;">额外的维护成本</span></em></li>
<li>查找翻阅索引系统需要消耗时间，索引存在<em><span style="color: #0000ff;">额外的访问成本</span></em></li>
<li>这个索引系统需要一个地方来存放，索引存在<em><span style="color: #0000ff;">额外的空间成本</span></em></li>
</ol>
</li>
<li><strong>索引是不是越多越好？ </strong>
<ol>
<li>如果我们的这个图书馆只是一个进出中转站，里面的新书进来后很快就会转发去其他图书馆而从这个馆藏中“清除”，那我们的索引就只会不断的修改，而很少会被用来查找图书<br />
<em><span style="color: #0000ff;"> 所以，对于类似于这样的存在非常大更新量的数据，索引的维护成本会非常高，如果其检索需求很少，而且对检索效率并没有非常高的要求的时候，我们并不建议创建索引，或者是尽量减少索引。</span></em></li>
<li>如果我们的书籍量少到只有几本或者就只有一个书架，索引并不会带来什么作用，甚至可能还会浪费一些查找索引所花费的时间。<br />
<em><span style="color: #0000ff;"> 所以，对于数据量极小到通过索引检索还不如直接遍历来得快的数据，也并不适合使用索引。</span></em></li>
<li>如果我们的图书馆只有一个10平方的面积，现在连放书架都已经非常拥挤，而且馆藏还在不断增加，我们还能考虑创建索引吗？<br />
<em><span style="color: #0000ff;"> 所以，当我们连存储基础数据的空间都捉襟见肘的时候，我们也应该尽量减少低效或者是去除索引。</span></em></li>
</ol>
</li>
<li><strong>索引该如何设计才高效？ </strong>
<ol>
<li>如果我们仅仅只是这样告诉对方的：“帮我确认一本数据库类别的讲述 MySQL 的叫做《MySQL性能调优与架构设计》的书是否在藏”，结果又会如何呢？朋友只能一个大类区域一个大类区域的去寻找“数据库”类别，然后再找到 “MySQL”范畴，再看到我们所需是否在藏。由于我们少说了一个“计算机类”，朋友就必须到每一个大类去寻找。<br />
<em><span style="color: #0000ff;"> 所以，我们应该尽量让查找条件尽可能多的在索引中，尽可能通过索引完成所有过滤，回表只是取出额外的数据字段。</span></em></li>
<li>如果我们是这样说的：“帮我确认一本讲述 MySQL 的数据库范畴的计算机丛书，叫做《MySQL性能调优与架构设计》，看是否在藏”。如果这位朋友并不知道计算机是一个大类，也不知道数据库属于计算机大类，那这位朋友就悲剧了。首先他得遍历每个类别确认“MySQL”存在于哪些类别中，然后从包含 “MySQL” 书籍中再看有哪些是“数据库”范畴的（有可能部分是讲述PHP或者其他开发语言的），然后再排除非计算机类的（虽然可能并没有必要），然后才能确认。<br />
<em><span style="color: #0000ff;"> 所以，字段的顺序对组合索引效率有至关重要的作用，过滤效果越好的字段需要更靠前。</span></em></li>
<li>如果我们还有这样一个需求（虽然基本不可能）：“帮我将图书馆中所有的计算机图书借来”。朋友如果通过索引来找，每次都到索引柜找到计算机书籍所在的区域，然后从书架上搬下一格（假设只能以一格为单位从书架上取下，类比数据库中以block/page为单位读取），取出第一本，然后再从索引柜找到计算机图书所在区域，再搬下一格，取出一本&#8230; 如此往复直至取完所有的书。如果他不通过索引来找又会怎样呢？他需要从地一个书架一直往后找，当找到计算机的书，搬下一格，取出所有计算机的书，再往后，直至所有书架全部看一遍。在这个过程中，如果计算机类书籍较多，通过索引来取所花费的时间很可能要大于直接遍历，因为不断往复的索引翻阅所消耗的时间会非常长。（延伸阅读：这里有一篇以前写的关于Oracle的文章，<a href="http://isky000.com/database/index_scan_or_full_table_scan">索引扫描还是全表扫描（Index Scan Or Full Table Scan）</a>）<br />
<em><span style="color: #0000ff;"> 所以，当我们需要读取的数据量占整个数据量的比例较大抑或者说索引的过滤效果并不是太好的时候，使用索引并不一定优于全表扫描。</span></em></li>
<li>如果我们的朋友不知道“数据库”这个类别可以属于“计算机”这个大类，抑或者图书馆的索引系统中这两个类别属性并没有关联关系，又会怎样呢？也就是说，朋友得到的是2个独立的索引，一个是告知“计算机”这个大类所在的区域，一个是“数据库”这个小类所在的区域（很可能是多个区域），那么他只能二者选其一来搜索我的需求。即使朋友可以分别通过2个索引检索然后自己在脑中取交集再找，那这样的效率实际过程中也会比较低下。<br />
<em><span style="color: #0000ff;"> 所以，在实际使用过程中，一次数据访问一般只能利用到1个索引，这一点在索引创建过程中一定要注意，不是说一条SQL语句中Where子句里面每个条件都有索引能对应上就可以了。</span></em></li>
</ol>
</li>
</ul>
<p>看完这些分析，我想大家应该了解索引优化的一些基本思路了吧 <img src='http://isky000.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/mysql-performance-tuning-index">http://isky000.com/database/mysql-performance-tuning-index</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">2012DTCC – 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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL 数据库性能优化之SQL优化</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?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-book-preview&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index">
                        <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" 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><img src="http://www1.feedsky.com/t1/628286869/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-performance-tuning-index" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/4YCiYy_R500qioy4eBLh_gA8eyM/0/da"><img src="http://feedads.g.doubleclick.net/~a/4YCiYy_R500qioy4eBLh_gA8eyM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/4YCiYy_R500qioy4eBLh_gA8eyM/1/da"><img src="http://feedads.g.doubleclick.net/~a/4YCiYy_R500qioy4eBLh_gA8eyM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/zsgvlpXpGko" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/mysql-performance-tuning-index/feed</wfw:commentRss><slash:comments>6</slash:comments><description>接着上一篇 MySQL 数据库性能优化之表结构，这是 MySQL数据库性能优化专题 系列的第三篇文章：MySQL 数据库性能优化之索引优化
大家都知道索引对于数据访问的性能有非常关键的作用，都知道索引可以提高数据访问效率。
为什么索引能提高数据访问性能？他会不会有“副作用”？是不是索引创建越多，性能就越好？到底该如何设计索引，才能最大限度的发挥其效能？
这篇文章主要是带着上面这几个问题来做一个简要的分析，同时排除了业务场景所带来的特殊性，请不要纠结业务场景的影响。

索引为什么能提高数据访问性能？
很多人只知道索引能够提高数据库的性能，但并不是特别了解其原理，其实我们可以用一个生活中的示例来理解。
我们让一位不太懂计算机的朋友去图书馆确认一本叫做《MySQL性能调优与架构设计》的书是否在藏，这样对他说：“请帮我借一本计算机类的数据库书籍，是属于 MySQL 数据库范畴的，叫做《MySQL性能调优与架构设计》”。朋友会根据所属类别，前往存放“计算机”书籍区域的书架，然后再寻找“数据库”类存放位置，再找到一堆讲述“MySQL”的书籍，最后可能发现目标在藏（也可能已经借出不在书架上）。
在这个过程中： “计算机”-&amp;#62;“数据库”-&amp;#62;“MySQL”-&amp;#62;“在藏”-&amp;#62;《MySQL性能调优与架构设计》其实就是一个“根据索引查找数据”的典型案例，“计算机”-&amp;#62;“数据库”-&amp;#62;“MySQL”-&amp;#62;“在藏” 就是朋友查找书籍的索引。
假设没有这个索引，那查找这本书的过程会变成怎样呢？朋友只能从图书馆入口一个书架一个书架的“遍历”，直到找到《MySQL性能调优与架构设计》这本书为止。如果幸运，可能在第一个书架就找到。但如果不幸呢，那就惨了，可能要将整个图书馆所有的书架都找一遍才能找到我们想要的这本书。
注：这个例子中的“索引”是记录在朋友大脑中的，实际上，每个图书馆都会有一个非常全的实际存在的索引系统（大多位于入口显眼处），由很多个贴上了明显标签的小抽屉构成。这个索引系统中存放这非常齐全详尽的索引数据，标识出我们需要查找的“目标”在某个区域的某个书架上。而且每当有新的书籍入库，旧的书籍销毁以及书记信息修改，都需要对索引系统进行及时的修正。


下面我们通过上面这个生活中的小示例，来分析一下索引，看看能的出哪些结论？

索引有哪些“副作用”？ 

图书的变更（增，删，改）都需要修订索引，索引存在额外的维护成本
查找翻阅索引系统需要消耗时间，索引存在额外的访问成本
这个索引系统需要一个地方来存放，索引存在额外的空间成本


索引是不是越多越好？ 

如果我们的这个图书馆只是一个进出中转站，里面的新书进来后很快就会转发去其他图书馆而从这个馆藏中“清除”，那我们的索引就只会不断的修改，而很少会被用来查找图书
 所以，对于类似于这样的存在非常大更新量的数据，索引的维护成本会非常高，如果其检索需求很少，而且对检索效率并没有非常高的要求的时候，我们并不建议创建索引，或者是尽量减少索引。
如果我们的书籍量少到只有几本或者就只有一个书架，索引并不会带来什么作用，甚至可能还会浪费一些查找索引所花费的时间。
 所以，对于数据量极小到通过索引检索还不如直接遍历来得快的数据，也并不适合使用索引。
如果我们的图书馆只有一个10平方的面积，现在连放书架都已经非常拥挤，而且馆藏还在不断增加，我们还能考虑创建索引吗？
 所以，当我们连存储基础数据的空间都捉襟见肘的时候，我们也应该尽量减少低效或者是去除索引。


索引该如何设计才高效？ 

如果我们仅仅只是这样告诉对方的：“帮我确认一本数据库类别的讲述 MySQL 的叫做《MySQL性能调优与架构设计》的书是否在藏”，结果又会如何呢？朋友只能一个大类区域一个大类区域的去寻找“数据库”类别，然后再找到 “MySQL”范畴，再看到我们所需是否在藏。由于我们少说了一个“计算机类”，朋友就必须到每一个大类去寻找。
 所以，我们应该尽量让查找条件尽可能多的在索引中，尽可能通过索引完成所有过滤，回表只是取出额外的数据字段。
如果我们是这样说的：“帮我确认一本讲述 MySQL 的数据库范畴的计算机丛书，叫做《MySQL性能调优与架构设计》，看是否在藏”。如果这位朋友并不知道计算机是一个大类，也不知道数据库属于计算机大类，那这位朋友就悲剧了。首先他得遍历每个类别确认“MySQL”存在于哪些类别中，然后从包含 “MySQL” 书籍中再看有哪些是“数据库”范畴的（有可能部分是讲述PHP或者其他开发语言的），然后再排除非计算机类的（虽然可能并没有必要），然后才能确认。
 所以，字段的顺序对组合索引效率有至关重要的作用，过滤效果越好的字段需要更靠前。
如果我们还有这样一个需求（虽然基本不可能）：“帮我将图书馆中所有的计算机图书借来”。朋友如果通过索引来找，每次都到索引柜找到计算机书籍所在的区域，然后从书架上搬下一格（假设只能以一格为单位从书架上取下，类比数据库中以block/page为单位读取），取出第一本，然后再从索引柜找到计算机图书所在区域，再搬下一格，取出一本&amp;#8230; 如此往复直至取完所有的书。如果他不通过索引来找又会怎样呢？他需要从地一个书架一直往后找，当找到计算机的书，搬下一格，取出所有计算机的书，再往后，直至所有书架全部看一遍。在这个过程中，如果计算机类书籍较多，通过索引来取所花费的时间很可能要大于直接遍历，因为不断往复的索引翻阅所消耗的时间会非常长。（延伸阅读：这里有一篇以前写的关于Oracle的文章，索引扫描还是全表扫描（Index Scan Or Full Table Scan））
 所以，当我们需要读取的数据量占整个数据量的比例较大抑或者说索引的过滤效果并不是太好的时候，使用索引并不一定优于全表扫描。
如果我们的朋友不知道“数据库”这个类别可以属于“计算机”这个大类，抑或者图书馆的索引系统中这两个类别属性并没有关联关系，又会怎样呢？也就是说，朋友得到的是2个独立的索引，一个是告知“计算机”这个大类所在的区域，一个是“数据库”这个小类所在的区域（很可能是多个区域），那么他只能二者选其一来搜索我的需求。即使朋友可以分别通过2个索引检索然后自己在脑中取交集再找，那这样的效率实际过程中也会比较低下。
 所以，在实际使用过程中，一次数据访问一般只能利用到1个索引，这一点在索引创建过程中一定要注意，不是说一条SQL语句中Where子句里面每个条件都有索引能对应上就可以了。



看完这些分析，我想大家应该了解索引优化的一些基本思路了吧  
作者： Sky.Jian &amp;#160;发布在：iSky000.com &amp;#160;欢迎&amp;#160;订阅本站FeedCopyright &amp;#169; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 版权声明 链接：http://isky000.com/database/mysql-performance-tuning-indexHosted On Dreamhost,折扣码 iMySQLer )&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之SQL优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Fmysql-book-preview&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;《MySQL性能调优与架构设计》即将上架&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286869/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-performance-tuning-index" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>MySQL数据库性能优化专题</category><category>MySQL</category><category>DataBase</category><category>performance tuning</category><pubDate>Wed, 23 Nov 2011 14:57:48 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/mysql-performance-tuning-index#comments</comments><guid isPermaLink="false">http://isky000.com/?p=1002</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/mysql-performance-tuning-index</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286869/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/mysql-performance-tuning-index</feedburner:origLink></item><item><title>数据驱动销售——个性化推荐引擎</title><link>http://feedproxy.google.com/~r/sky000/~3/WvQWw_nHAk0/data-drive-sale-recommendation</link><content:encoded><![CDATA[<p>这是之前发布于<a href="http://www.programmer.com.cn/7614/">《程序员》杂志2011年08期的一篇文章</a>，这里再在Blog上发布一下。</p>
<p>在当前这个信息量飞速增长的时代，一个企业，尤其是电子商务企业的成功已经越来越多地与其海量数据处理能力相关联。高效、迅速地从海量数据中挖掘出潜在价值并转化为决策依据的能力，将成为企业的核心竞争力。</p>
<p>数据的重要性毋庸置疑，但随着数据的产生速度越来越快，数据量越来越大，数据处理技术的挑战自然也越来越大。如何从海量数据中挖掘出价值所在，分析出深层含义，进而转化为可操作的信息，已经成为各互联网企业尤其是电子商务公司不得不研究的课题。本文将介绍国内箱包行业电子商务领军者麦包包如何利用海量数据的分析处理（个性化推荐引擎）来协助用户更好地完成购买体验。</p>
<dl id="attachment_7725">
<dt><a href="http://www.programmer.com.cn/wp-content/uploads/2011/08/csdn1.jpg"><img title="csdn1" src="http://www.programmer.com.cn/wp-content/uploads/2011/08/csdn1-300x207.jpg" alt="图1 数据层基础架构" width="300" height="207" /></a></dt>
<dd>图1 数据层基础架构</p>
</dd>
</dl>
<p><strong> </strong></p>
<p><strong>数据层基础架构</strong></p>
<p>如图1所示，麦包包的数据层基础架构与其他很多互联网公司相比，可能会有一点儿差异，那就是有一个用于实时分析处理的在线分析数据层，用来处理一些对实时性要求较高的分析任务。<br />
总的来说，麦包包的数据层分为下面三个部分。</p>
<ul>
<li><strong>在线交易数据层</strong></li>
</ul>
<p>用于存放网站对外访问数据，如交易相关、产品相关、用户相关等数据。</p>
<ul>
<li><strong>离线分析数据层</strong></li>
</ul>
<p>用于分析各种报表、数据挖掘，如购买行为、销售分析、浏览跟踪等。</p>
<ul>
<li><strong>在线分析数据层</strong></li>
</ul>
<p>用于处理一些对实时性要求较高的分析，如在线交易分析、用户浏览推荐等。在线交易数据层和离线分析数据层对于大家来说都已经比较熟悉了，二者的数据特点和访问特点都很清晰明确，架构方向也相对明确。只有在线分析系统比较特别，既有高并发的用户访问，同时又兼具了分析型复杂查询及海量的基础数据，构建起来相对要复杂一些。所以下面简单介绍一下麦包包如何构建在线分析系统的应用之一——“个性化推荐引擎”。<strong> </strong></p>
<p><strong>个性化推荐引擎</strong></p>
<p>我们首先分析一下这个推荐引擎的需求。</p>
<ul>
<li><strong>关联个性化</strong></li>
</ul>
<p>根据用户的喜好倾向以及访问历史记录，不同用户浏览同一个产品时，将给出不同的关联推荐结果。</p>
<ul>
<li><strong>页面个性化</strong></li>
</ul>
<p>不同用户访问同一个页面，我们将会根据用户的以往购买历史及浏览行为而展示个性化的内容。</p>
<ul>
<li><strong>搜索个性化</strong></li>
</ul>
<p>随着用户的多次搜索及结果点击行为，我们会对搜索结果进行过滤重组，尽可能展示更符合用户需求的搜索结果。也就是说，在完全相同的基础数据中，不同用户在同一时间搜索同一个关键词，可能会给出不一样的结果；或者同一个用户重复多次搜索同一个关键词，也可能会有不一样的结果。</p>
<p>我们再来看一看推荐引擎的数据特点。</p>
<ul>
<li><strong>海量</strong></li>
</ul>
<p>超过500万会员，5位数的SKU，7位数的访问量。将这些数据与会员及SKU的各类属性相互关联，数据量之庞大可想而知。</p>
<ul>
<li><strong>多维度</strong></li>
</ul>
<p>从性能优化角度来说，数据量大并不可怕，只要访问方式简单，很容易通过索引等手段进行优化。可偏偏不幸的是，由于将用户和产品进行多维度关联，既需要根据用户去分析，又需要根据产品去关联，再辅以运行时的各类属性；既可能各个维度同时存在，也可能只有任何一个维度；多维度就多维度吧，可还有很多访问是分析型，比较难以优化扩展。</p>
<ul>
<li><strong>访问高并发</strong></li>
</ul>
<p>当然，数据量大也并不一定就可怕，如果并发访问较小，响应时间要求不是太高，那也容易解决，可以用Hadoop之类的分布式系统来分析计算。可恰恰不巧的就是这个系统面对的是网站上的访问客户，对并发及响应时间的要求和OLTP系统一样。</p>
<p>需求已经确定，数据特点也已了解，下一步就是根据数据的特点，设计一个切实可行的架构来实现这些应用需求了。</p>
<p>在如此<strong>海量</strong>数据中进行<strong>高并发</strong>的<strong>复杂分析查询</strong>，还要能够快速响应，看上去就像是一个不可能的任务。但仔细分析之后，我们不难发现，推荐引擎结果主要由以下几个因素决定。</p>
<ul>
<li><strong>用户固定属性</strong>：年龄、性别、职业类型、地域、价格承受范围、色彩喜好、品牌喜好等。</li>
</ul>
<ul>
<li><strong>产品固定属性</strong>：品牌、类别、材质、价格、色系等。</li>
</ul>
<ul>
<li><strong>用户以往行为</strong>：浏览历史、购买历史等。</li>
</ul>
<ul>
<li><strong>用户当前行为</strong>：当前点击、浏览等。</li>
</ul>
<p>以上四个因素实际上对应了四种数据，在分析每一种数据的特点之后，可以发现前面三个因素所对应的数据都是相对静态的，只有用户当前行为才是一个在不断变化的动态数据。也就是说，在海量数据中，只有少部分数据是动态的，其他大部分都是静态。<br />
当然，用户属性中的各种喜好，也需要我们通过用户以往的历史购买以及浏览行为进行各种分析挖掘才能获得，但这都是由历史积淀数据分析得来，而不是由当前的运行时动态数据决定。价格承受范围以及地域特性也同样如此。</p>
<p>数据的这一特性对我们的架构设计起到了一个非常关键的作用，因为我们可以使用完全不同的方式来将静态数据和动态数据分开处理，再合并分析。静态数据的变化较小，实时性要求较低，我们将进行离线分析；动态数据相对较少，但实时性要求较高，我们在线实时处理。动、静数据在线合并分析。这样一来，我们就可以很轻松地绕过海量数据的高并发在线分析的问题，将这一动作交由离线分析系统定时作业批量完成，既不会有高并发问题，又不存在响应时间的压力。至于在线实时数据的处理，由于数据量的大幅缩减，以及访问方式的简化，比在线交易的OLTP系统复杂度高不了太多，自然也就容易优化了。</p>
<dl id="attachment_7726">
<dt><a href="http://www.programmer.com.cn/wp-content/uploads/2011/08/csdn2.jpg"><img title="csdn2" src="http://www.programmer.com.cn/wp-content/uploads/2011/08/csdn2-300x202.jpg" alt="图2 推荐引擎基本架构" width="300" height="202" /></a></dt>
<dd>图2 推荐引擎基本架构</p>
</dd>
</dl>
<p><strong>架构设计</strong></p>
<p>简单来说，推荐引擎系统本身的基础架构就如图2所展现的一样，一部分数据进行离线计算，另一部分数据在线计算合并，最终通过推荐引擎API将数据处理后返回给前端应用。</p>
<p>看上去简单，但有几个问题并没有展现出来，那就是离线计算和在线计算这两部分具体是如何构建的？数据如何进入离线计算系统？又如何将离线运算结果回送至在线计算系统中？最终数据又如何交由前端应用使用？让我们再来看看图3。</p>
<p>离线分析层完全可以通过成熟的产品来构建，如Greenplum、Hadoop等，目前我们已经使用了Greeplum，后续很快还会引入Hadoop，通过HBase + Hive来对处理我们的用户与各SKU的关系数据，帮助进一步完善我们的协同过滤算法，进而优化推荐引擎。在线合并分析层我们选择MySQL数据库。可能有些人会问，为什么不使用当前如此流行的NoSQL产品呢？主要原因有以下两点。</p>
<ul>
<li>MySQL更便于维护与备份等运维需求。</li>
</ul>
<ul>
<li>NoSQL不满足我们的一些分析型查询需求。</li>
</ul>
<p>NoSQL产品虽然流行，但每种产品都还只适于某些特定的应用场景，很多听上去完美的理论目前暂时还仅仅只是听上去完美，实际用起来仍然存在各种各样的问题。所以我们选择了更适合于我们的MySQL作为在线合并分析层的数据库。</p>
<div id="attachment_7727">
<p><a href="http://www.programmer.com.cn/wp-content/uploads/2011/08/csdn3.jpg"><img title="csdn3" src="http://www.programmer.com.cn/wp-content/uploads/2011/08/csdn3-300x199.jpg" alt="图3 推荐引擎整体架构" width="300" height="199" /></a>图3 推荐引擎整体架构</p>
</div>
<p>整个架构的数据流，如图3所示。</p>
<ul>
<li>前端应用产生用户的浏览日志、购买日志、搜索日志以及用户及产品属性数据进入。</li>
</ul>
<ul>
<li>通过文件日志收集程序以及基于MySQL开放复制协议所定制的数据同步工具（注：在我的个人网站上有介绍：http://isky000.com/database/mysql-replication-extend）将数据同步至离线分析系统中。</li>
</ul>
<ul>
<li>通过离线任务的统计分析，得出会员的各种喜好属性，并将之与产品属性进行关联分析，得出一个用户产品倾向性关联结果，然后再通过应用程序定期从离线分析系统将上述分析结果写入在线合并分析数据库中。</li>
</ul>
<ul>
<li>推荐引擎根据前端应用（如Search）传入的用户当前运行时操作属性，与在线合并分析数据库中属性进行合并（Merge），再过滤（Filter）。</li>
</ul>
<ul>
<li>前端应用从推荐引擎处获取Merge与Filter之后的数据，再在前端页面上完成展现。</li>
</ul>
<p>以上就是整个推荐引擎的数据流架构方案，乍一看也没有太多特别的内容，但在实际实施过程中，会遇到以下几个难点。</p>
<ul>
<li><strong>各种日志传输到离线分析系统，如何做到尽可能实时并不影响在线系统。</strong></li>
</ul>
<p>这个难点，我们首先在每一个页面部署监测点，通过请求一个gif图片来获得用户的各种浏览信息，并存入到MySQL数据库，交易相关的数据自然也会有在数据库中进行存储。然后使用通过扩展MySQL复制协议而实现的日志解析合并程序，实时解析 MySQL日志，再将其以我们需要的格式传输至离线分析系统中进行分析运算。</p>
<ul>
<li><strong>如何将用户的运行时操作属性与我们的离线分析结果进行Merge及Filte。</strong></li>
</ul>
<p>这个难点，实际上在6月刊的《程序员》杂志对麦包包首席架构师盛国军的采访稿中，已经有了相应的介绍。我们主要使用了基于用户（User）、商品（Item）、话题（Topic）以及曝光（Exposure）这四种协同过滤技术，来实现推荐算法。</p>
<p>总的来说，数据量的增长，以及分析需求的越来越复杂，将会对互联网公司的数据处理能力提出越来越高的要求、越来越大的挑战。但每一个场景都有其特性，充分分析其数据特性，将合适的软件用在合适的场景下，才能更好地解决实际问题。</p>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/data-drive-sale-recommendation">http://isky000.com/database/data-drive-sale-recommendation</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-replication-principle&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL Replication(复制)基本原理</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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">2012DTCC – 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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql_patch_mirroredbinlogs_from_google&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL Patch – MirroredBinlogs (From Google)</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" 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><img src="http://www1.feedsky.com/t1/628286870/sky000/feedsky/s.gif?r=http://isky000.com/database/data-drive-sale-recommendation" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/Uqh7Ft39V1vPl4ZS1Tkk_pYk-Ww/0/da"><img src="http://feedads.g.doubleclick.net/~a/Uqh7Ft39V1vPl4ZS1Tkk_pYk-Ww/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Uqh7Ft39V1vPl4ZS1Tkk_pYk-Ww/1/da"><img src="http://feedads.g.doubleclick.net/~a/Uqh7Ft39V1vPl4ZS1Tkk_pYk-Ww/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/WvQWw_nHAk0" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/data-drive-sale-recommendation/feed</wfw:commentRss><slash:comments>4</slash:comments><description>这是之前发布于《程序员》杂志2011年08期的一篇文章，这里再在Blog上发布一下。
在当前这个信息量飞速增长的时代，一个企业，尤其是电子商务企业的成功已经越来越多地与其海量数据处理能力相关联。高效、迅速地从海量数据中挖掘出潜在价值并转化为决策依据的能力，将成为企业的核心竞争力。
数据的重要性毋庸置疑，但随着数据的产生速度越来越快，数据量越来越大，数据处理技术的挑战自然也越来越大。如何从海量数据中挖掘出价值所在，分析出深层含义，进而转化为可操作的信息，已经成为各互联网企业尤其是电子商务公司不得不研究的课题。本文将介绍国内箱包行业电子商务领军者麦包包如何利用海量数据的分析处理（个性化推荐引擎）来协助用户更好地完成购买体验。


图1 数据层基础架构


 
数据层基础架构
如图1所示，麦包包的数据层基础架构与其他很多互联网公司相比，可能会有一点儿差异，那就是有一个用于实时分析处理的在线分析数据层，用来处理一些对实时性要求较高的分析任务。
总的来说，麦包包的数据层分为下面三个部分。

在线交易数据层

用于存放网站对外访问数据，如交易相关、产品相关、用户相关等数据。

离线分析数据层

用于分析各种报表、数据挖掘，如购买行为、销售分析、浏览跟踪等。

在线分析数据层

用于处理一些对实时性要求较高的分析，如在线交易分析、用户浏览推荐等。在线交易数据层和离线分析数据层对于大家来说都已经比较熟悉了，二者的数据特点和访问特点都很清晰明确，架构方向也相对明确。只有在线分析系统比较特别，既有高并发的用户访问，同时又兼具了分析型复杂查询及海量的基础数据，构建起来相对要复杂一些。所以下面简单介绍一下麦包包如何构建在线分析系统的应用之一——“个性化推荐引擎”。 
个性化推荐引擎
我们首先分析一下这个推荐引擎的需求。

关联个性化

根据用户的喜好倾向以及访问历史记录，不同用户浏览同一个产品时，将给出不同的关联推荐结果。

页面个性化

不同用户访问同一个页面，我们将会根据用户的以往购买历史及浏览行为而展示个性化的内容。

搜索个性化

随着用户的多次搜索及结果点击行为，我们会对搜索结果进行过滤重组，尽可能展示更符合用户需求的搜索结果。也就是说，在完全相同的基础数据中，不同用户在同一时间搜索同一个关键词，可能会给出不一样的结果；或者同一个用户重复多次搜索同一个关键词，也可能会有不一样的结果。
我们再来看一看推荐引擎的数据特点。

海量

超过500万会员，5位数的SKU，7位数的访问量。将这些数据与会员及SKU的各类属性相互关联，数据量之庞大可想而知。

多维度

从性能优化角度来说，数据量大并不可怕，只要访问方式简单，很容易通过索引等手段进行优化。可偏偏不幸的是，由于将用户和产品进行多维度关联，既需要根据用户去分析，又需要根据产品去关联，再辅以运行时的各类属性；既可能各个维度同时存在，也可能只有任何一个维度；多维度就多维度吧，可还有很多访问是分析型，比较难以优化扩展。

访问高并发

当然，数据量大也并不一定就可怕，如果并发访问较小，响应时间要求不是太高，那也容易解决，可以用Hadoop之类的分布式系统来分析计算。可恰恰不巧的就是这个系统面对的是网站上的访问客户，对并发及响应时间的要求和OLTP系统一样。
需求已经确定，数据特点也已了解，下一步就是根据数据的特点，设计一个切实可行的架构来实现这些应用需求了。
在如此海量数据中进行高并发的复杂分析查询，还要能够快速响应，看上去就像是一个不可能的任务。但仔细分析之后，我们不难发现，推荐引擎结果主要由以下几个因素决定。

用户固定属性：年龄、性别、职业类型、地域、价格承受范围、色彩喜好、品牌喜好等。


产品固定属性：品牌、类别、材质、价格、色系等。


用户以往行为：浏览历史、购买历史等。


用户当前行为：当前点击、浏览等。

以上四个因素实际上对应了四种数据，在分析每一种数据的特点之后，可以发现前面三个因素所对应的数据都是相对静态的，只有用户当前行为才是一个在不断变化的动态数据。也就是说，在海量数据中，只有少部分数据是动态的，其他大部分都是静态。
当然，用户属性中的各种喜好，也需要我们通过用户以往的历史购买以及浏览行为进行各种分析挖掘才能获得，但这都是由历史积淀数据分析得来，而不是由当前的运行时动态数据决定。价格承受范围以及地域特性也同样如此。
数据的这一特性对我们的架构设计起到了一个非常关键的作用，因为我们可以使用完全不同的方式来将静态数据和动态数据分开处理，再合并分析。静态数据的变化较小，实时性要求较低，我们将进行离线分析；动态数据相对较少，但实时性要求较高，我们在线实时处理。动、静数据在线合并分析。这样一来，我们就可以很轻松地绕过海量数据的高并发在线分析的问题，将这一动作交由离线分析系统定时作业批量完成，既不会有高并发问题，又不存在响应时间的压力。至于在线实时数据的处理，由于数据量的大幅缩减，以及访问方式的简化，比在线交易的OLTP系统复杂度高不了太多，自然也就容易优化了。


图2 推荐引擎基本架构


架构设计
简单来说，推荐引擎系统本身的基础架构就如图2所展现的一样，一部分数据进行离线计算，另一部分数据在线计算合并，最终通过推荐引擎API将数据处理后返回给前端应用。
看上去简单，但有几个问题并没有展现出来，那就是离线计算和在线计算这两部分具体是如何构建的？数据如何进入离线计算系统？又如何将离线运算结果回送至在线计算系统中？最终数据又如何交由前端应用使用？让我们再来看看图3。
离线分析层完全可以通过成熟的产品来构建，如Greenplum、Hadoop等，目前我们已经使用了Greeplum，后续很快还会引入Hadoop，通过HBase + Hive来对处理我们的用户与各SKU的关系数据，帮助进一步完善我们的协同过滤算法，进而优化推荐引擎。在线合并分析层我们选择MySQL数据库。可能有些人会问，为什么不使用当前如此流行的NoSQL产品呢？主要原因有以下两点。

MySQL更便于维护与备份等运维需求。


NoSQL不满足我们的一些分析型查询需求。

NoSQL产品虽然流行，但每种产品都还只适于某些特定的应用场景，很多听上去完美的理论目前暂时还仅仅只是听上去完美，实际用起来仍然存在各种各样的问题。所以我们选择了更适合于我们的MySQL作为在线合并分析层的数据库。

图3 推荐引擎整体架构

整个架构的数据流，如图3所示。

前端应用产生用户的浏览日志、购买日志、搜索日志以及用户及产品属性数据进入。


通过文件日志收集程序以及基于MySQL开放复制协议所定制的数据同步工具（注：在我的个人网站上有介绍：http://isky000.com/database/mysql-replication-extend）将数据同步至离线分析系统中。


通过离线任务的统计分析，得出会员的各种喜好属性，并将之与产品属性进行关联分析，得出一个用户产品倾向性关联结果，然后再通过应用程序定期从离线分析系统将上述分析结果写入在线合并分析数据库中。


推荐引擎根据前端应用（如Search）传入的用户当前运行时操作属性，与在线合并分析数据库中属性进行合并（Merge），再过滤（Filter）。


前端应用从推荐引擎处获取Merge与Filter之后的数据，再在前端页面上完成展现。

以上就是整个推荐引擎的数据流架构方案，乍一看也没有太多特别的内容，但在实际实施过程中，会遇到以下几个难点。

各种日志传输到离线分析系统，如何做到尽可能实时并不影响在线系统。

这个难点，我们首先在每一个页面部署监测点，通过请求一个gif图片来获得用户的各种浏览信息，并存入到MySQL数据库，交易相关的数据自然也会有在数据库中进行存储。然后使用通过扩展MySQL复制协议而实现的日志解析合并程序，实时解析 MySQL日志，再将其以我们需要的格式传输至离线分析系统中进行分析运算。

如何将用户的运行时操作属性与我们的离线分析结果进行Merge及Filte。

这个难点，实际上在6月刊的《程序员》杂志对麦包包首席架构师盛国军的采访稿中，已经有了相应的介绍。我们主要使用了基于用户（User）、商品（Item）、话题（Topic）以及曝光（Exposure）这四种协同过滤技术，来实现推荐算法。
总的来说，数据量的增长，以及分析需求的越来越复杂，将会对互联网公司的数据处理能力提出越来越高的要求、越来越大的挑战。但每一个场景都有其特性，充分分析其数据特性，将合适的软件用在合适的场景下，才能更好地解决实际问题。
作者： Sky.Jian &amp;#160;发布在：iSky000.com &amp;#160;欢迎&amp;#160;订阅本站FeedCopyright &amp;#169; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 版权声明 链接：http://isky000.com/database/data-drive-sale-recommendationHosted On Dreamhost,折扣码 iMySQLer )&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-replication-principle&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL Replication(复制)基本原理&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql_patch_mirroredbinlogs_from_google&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fdata-drive-sale-recommendation"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL Patch – MirroredBinlogs (From Google)&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286870/sky000/feedsky/s.gif?r=http://isky000.com/database/data-drive-sale-recommendation" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>replication</category><category>MySQL</category><category>DataBase</category><category>recommendation</category><pubDate>Mon, 07 Nov 2011 10:33:11 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/data-drive-sale-recommendation#comments</comments><guid isPermaLink="false">http://isky000.com/?p=997</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/data-drive-sale-recommendation</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286870/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/data-drive-sale-recommendation</feedburner:origLink></item><item><title>MySQL 数据库性能优化之表结构优化</title><link>http://feedproxy.google.com/~r/sky000/~3/yJ0R3kyQbL0/mysql-perfornamce-tuning-schema</link><content:encoded><![CDATA[<p>接着上一篇 <strong><a title="Permanent Link to MySQL 数据库性能优化之缓存参数优化" href="http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter">MySQL 数据库性能优化之缓存参数优化</a> </strong>，这是 <strong>MySQL数据库性能优化专题</strong> 系列的第二篇文章：<a href="http://isky000.com/database/mysql-perfornamce-tuning-schema">MySQL 数据库性能优化之表结构</a></p>
<p>很多人都将 <strong>数据库设计范式</strong> 作为数据库表结构设计“圣经”，认为只要按照这个范式需求设计，就能让设计出来的表结构足够优化，既能保证性能优异同时还能满足扩展性要求。殊不知，在N年前被奉为“圣经”的数据库设计3范式早就已经不完全适用了。这里我整理了一些比较常见的数据库表结构设计方面的优化技巧，希望对大家有用。</p>
<p>由于MySQL数据库是基于行（Row）存储的数据库，而数据库操作 IO 的时候是以 page（block）的方式，也就是说，如果我们每条记录所占用的空间量减小，就会使每个page中可存放的数据行数增大，那么每次 IO 可访问的行数也就增多了。反过来说，处理相同行数的数据，需要访问的 page 就会减少，也就是 IO 操作次数降低，直接提升性能。此外，由于我们的内存是有限的，增加每个page中存放的数据行数，就等于增加每个内存块的缓存数据量，同时还会提升内存换中数据命中的几率，也就是缓存命中率。</p>
<ul>
<li>数据类型选择<br />
数据库操作中最为耗时的操作就是 IO 处理，大部分数据库操作 90% 以上的时间都花在了 IO 读写上面。所以尽可能减少 IO 读写量，可以在很大程度上提高数据库操作的性能。</p>
<p>我们无法改变数据库中需要存储的数据，但是我们可以在这些数据的存储方式方面花一些心思。下面的这些关于字段类型的优化建议主要适用于记录条数较多，数据量较大的场景，因为精细化的数据类型设置可能带来维护成本的提高，过度优化也可能会带来其他的问题：</p>
<ol>
<li>数字类型：非万不得已不要使用DOUBLE，不仅仅只是存储长度的问题，同时还会存在精确性的问题。同样，固定精度的小数，也不建议使用DECIMAL，建议乘以固定倍数转换成整数存储，可以大大节省存储空间，且不会带来任何附加维护成本。对于整数的存储，在数据量较大的情况下，建议区分开 TINYINT / INT / BIGINT 的选择，因为三者所占用的存储空间也有很大的差别，能确定不会使用负数的字段，建议添加unsigned定义。当然，如果数据量较小的数据库，也可以不用严格区分三个整数类型。</li>
<li>字符类型：非万不得已不要使用 TEXT 数据类型，其处理方式决定了他的性能要低于char或者是varchar类型的处理。定长字段，建议使用 CHAR 类型，不定长字段尽量使用 VARCHAR，且仅仅设定适当的最大长度，而不是非常随意的给一个很大的最大长度限定，因为不同的长度范围，MySQL也会有不一样的存储处理。</li>
<li>时间类型：尽量使用TIMESTAMP类型，因为其存储空间只需要 DATETIME 类型的一半。对于只需要精确到某一天的数据类型，建议使用DATE类型，因为他的存储空间只需要3个字节，比TIMESTAMP还少。不建议通过INT类型类存储一个unix timestamp 的值，因为这太不直观，会给维护带来不必要的麻烦，同时还不会带来任何好处。</li>
<li>ENUM &amp; SET：对于状态字段，可以尝试使用 ENUM 来存放，因为可以极大的降低存储空间，而且即使需要增加新的类型，只要增加于末尾，修改结构也不需要重建表数据。如果是存放可预先定义的属性数据呢？可以尝试使用SET类型，即使存在多种属性，同样可以游刃有余，同时还可以节省不小的存储空间。</li>
<li>LOB类型：强烈反对在数据库中存放 LOB 类型数据，虽然数据库提供了这样的功能，但这不是他所擅长的，我们更应该让合适的工具做他擅长的事情，才能将其发挥到极致。在数据库中存储 LOB 数据就像让一个多年前在学校学过一点Java的营销专业人员来写 Java 代码一样。</li>
</ol>
</li>
<li>字符编码<br />
字符集直接决定了数据在MySQL中的存储编码方式，由于同样的内容使用不同字符集表示所占用的空间大小会有较大的差异，所以通过使用合适的字符集，可以帮助我们尽可能减少数据量，进而减少IO操作次数。</p>
<ol>
<li>纯拉丁字符能表示的内容，没必要选择 latin1 之外的其他字符编码，因为这会节省大量的存储空间</li>
<li>如果我们可以确定不需要存放多种语言，就没必要非得使用UTF8或者其他UNICODE字符类型，这回造成大量的存储空间浪费</li>
<li>MySQL的数据类型可以精确到字段，所以当我们需要大型数据库中存放多字节数据的时候，可以通过对不同表不同字段使用不同的数据类型来较大程度减小数据存储量，进而降低 IO 操作次数并提高缓存命中率</li>
</ol>
</li>
<li>适当拆分<br />
有些时候，我们可能会希望将一个完整的对象对应于一张数据库表，这对于应用程序开发来说是很有好的，但是有些时候可能会在性能上带来较大的问题。</p>
<p>当我们的表中存在类似于 TEXT 或者是很大的 VARCHAR类型的大字段的时候，如果我们大部分访问这张表的时候都不需要这个字段，我们就该义无反顾的将其拆分到另外的独立表中，以减少常用数据所占用的存储空间。这样做的一个明显好处就是每个数据块中可以存储的数据条数可以大大增加，既减少物理 IO 次数，也能大大提高内存中的缓存命中率。</li>
</ul>
<p>上面几点的优化都是为了减少每条记录的存储空间大小，让每个数据库中能够存储更多的记录条数，以达到减少 IO 操作次数，提高缓存命中率。下面这个优化建议可能很多开发人员都会觉得不太理解，因为这是典型的反范式设计，而且也和上面的几点优化建议的目标相违背。</p>
<ul>
<li>适度冗余<br />
为什么我们要冗余？这不是增加了每条数据的大小，减少了每个数据块可存放记录条数吗？</p>
<p>确实，这样做是会增大每条记录的大小，降低每条记录中可存放数据的条数，但是在有些场景下我们仍然还是不得不这样做：</p>
<ol>
<li>被频繁引用且只能通过 Join 2张（或者更多）大表的方式才能得到的独立小字段<br />
这样的场景由于每次Join仅仅只是为了取得某个小字段的值，Join到的记录又大，会造成大量不必要的 IO，完全可以通过空间换取时间的方式来优化。不过，冗余的同时需要确保数据的一致性不会遭到破坏，确保更新的同时冗余字段也被更新</li>
</ol>
</li>
<li>尽量使用 NOT NULL<br />
NULL 类型比较特殊，SQL 难优化。虽然 MySQL NULL类型和 Oracle 的NULL 有差异，会进入索引中，但如果是一个组合索引，那么这个NULL 类型的字段会极大影响整个索引的效率。此外，NULL 在索引中的处理也是特殊的，也会占用额外的存放空间。<br />
很多人觉得 NULL 会节省一些空间，所以尽量让NULL来达到节省IO的目的，但是大部分时候这会适得其反，虽然空间上可能确实有一定节省，倒是带来了很多其他的优化问题，不但没有将IO量省下来，反而加大了SQL的IO量。所以尽量确保 DEFAULT 值不是 NULL，也是一个很好的表结构设计优化习惯。</li>
</ul>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/mysql-perfornamce-tuning-schema">http://isky000.com/database/mysql-perfornamce-tuning-schema</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">2012DTCC – 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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL 数据库性能优化之SQL优化</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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema">
                        <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" 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><img src="http://www1.feedsky.com/t1/628286871/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-perfornamce-tuning-schema" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/qqlS-T3DSNeBmn-9SMMbUg1lG00/0/da"><img src="http://feedads.g.doubleclick.net/~a/qqlS-T3DSNeBmn-9SMMbUg1lG00/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qqlS-T3DSNeBmn-9SMMbUg1lG00/1/da"><img src="http://feedads.g.doubleclick.net/~a/qqlS-T3DSNeBmn-9SMMbUg1lG00/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/yJ0R3kyQbL0" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/mysql-perfornamce-tuning-schema/feed</wfw:commentRss><slash:comments>5</slash:comments><description>接着上一篇 MySQL 数据库性能优化之缓存参数优化 ，这是 MySQL数据库性能优化专题 系列的第二篇文章：MySQL 数据库性能优化之表结构
很多人都将 数据库设计范式 作为数据库表结构设计“圣经”，认为只要按照这个范式需求设计，就能让设计出来的表结构足够优化，既能保证性能优异同时还能满足扩展性要求。殊不知，在N年前被奉为“圣经”的数据库设计3范式早就已经不完全适用了。这里我整理了一些比较常见的数据库表结构设计方面的优化技巧，希望对大家有用。
由于MySQL数据库是基于行（Row）存储的数据库，而数据库操作 IO 的时候是以 page（block）的方式，也就是说，如果我们每条记录所占用的空间量减小，就会使每个page中可存放的数据行数增大，那么每次 IO 可访问的行数也就增多了。反过来说，处理相同行数的数据，需要访问的 page 就会减少，也就是 IO 操作次数降低，直接提升性能。此外，由于我们的内存是有限的，增加每个page中存放的数据行数，就等于增加每个内存块的缓存数据量，同时还会提升内存换中数据命中的几率，也就是缓存命中率。

数据类型选择
数据库操作中最为耗时的操作就是 IO 处理，大部分数据库操作 90% 以上的时间都花在了 IO 读写上面。所以尽可能减少 IO 读写量，可以在很大程度上提高数据库操作的性能。
我们无法改变数据库中需要存储的数据，但是我们可以在这些数据的存储方式方面花一些心思。下面的这些关于字段类型的优化建议主要适用于记录条数较多，数据量较大的场景，因为精细化的数据类型设置可能带来维护成本的提高，过度优化也可能会带来其他的问题：

数字类型：非万不得已不要使用DOUBLE，不仅仅只是存储长度的问题，同时还会存在精确性的问题。同样，固定精度的小数，也不建议使用DECIMAL，建议乘以固定倍数转换成整数存储，可以大大节省存储空间，且不会带来任何附加维护成本。对于整数的存储，在数据量较大的情况下，建议区分开 TINYINT / INT / BIGINT 的选择，因为三者所占用的存储空间也有很大的差别，能确定不会使用负数的字段，建议添加unsigned定义。当然，如果数据量较小的数据库，也可以不用严格区分三个整数类型。
字符类型：非万不得已不要使用 TEXT 数据类型，其处理方式决定了他的性能要低于char或者是varchar类型的处理。定长字段，建议使用 CHAR 类型，不定长字段尽量使用 VARCHAR，且仅仅设定适当的最大长度，而不是非常随意的给一个很大的最大长度限定，因为不同的长度范围，MySQL也会有不一样的存储处理。
时间类型：尽量使用TIMESTAMP类型，因为其存储空间只需要 DATETIME 类型的一半。对于只需要精确到某一天的数据类型，建议使用DATE类型，因为他的存储空间只需要3个字节，比TIMESTAMP还少。不建议通过INT类型类存储一个unix timestamp 的值，因为这太不直观，会给维护带来不必要的麻烦，同时还不会带来任何好处。
ENUM &amp;#38; SET：对于状态字段，可以尝试使用 ENUM 来存放，因为可以极大的降低存储空间，而且即使需要增加新的类型，只要增加于末尾，修改结构也不需要重建表数据。如果是存放可预先定义的属性数据呢？可以尝试使用SET类型，即使存在多种属性，同样可以游刃有余，同时还可以节省不小的存储空间。
LOB类型：强烈反对在数据库中存放 LOB 类型数据，虽然数据库提供了这样的功能，但这不是他所擅长的，我们更应该让合适的工具做他擅长的事情，才能将其发挥到极致。在数据库中存储 LOB 数据就像让一个多年前在学校学过一点Java的营销专业人员来写 Java 代码一样。


字符编码
字符集直接决定了数据在MySQL中的存储编码方式，由于同样的内容使用不同字符集表示所占用的空间大小会有较大的差异，所以通过使用合适的字符集，可以帮助我们尽可能减少数据量，进而减少IO操作次数。

纯拉丁字符能表示的内容，没必要选择 latin1 之外的其他字符编码，因为这会节省大量的存储空间
如果我们可以确定不需要存放多种语言，就没必要非得使用UTF8或者其他UNICODE字符类型，这回造成大量的存储空间浪费
MySQL的数据类型可以精确到字段，所以当我们需要大型数据库中存放多字节数据的时候，可以通过对不同表不同字段使用不同的数据类型来较大程度减小数据存储量，进而降低 IO 操作次数并提高缓存命中率


适当拆分
有些时候，我们可能会希望将一个完整的对象对应于一张数据库表，这对于应用程序开发来说是很有好的，但是有些时候可能会在性能上带来较大的问题。
当我们的表中存在类似于 TEXT [...]&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之SQL优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-schema"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之索引优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286871/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-perfornamce-tuning-schema" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>MySQL数据库性能优化专题</category><category>MySQL</category><category>DataBase</category><category>performance tuning</category><pubDate>Thu, 27 Oct 2011 13:40:29 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/mysql-perfornamce-tuning-schema#comments</comments><guid isPermaLink="false">http://isky000.com/?p=989</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/mysql-perfornamce-tuning-schema</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286871/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/mysql-perfornamce-tuning-schema</feedburner:origLink></item><item><title>MySQL 数据库性能优化之缓存参数优化</title><link>http://feedproxy.google.com/~r/sky000/~3/UBrCt54vqLw/mysql-perfornamce-tuning-cache-parameter</link><content:encoded><![CDATA[<p>在平时被问及最多的问题就是关于 MySQL 数据库性能优化方面的问题，所以最近打算写一个<strong>MySQL数据库性能优化</strong>方面的系列文章，希望对初中级 MySQL DBA 以及其他对 MySQL 性能优化感兴趣的朋友们有所帮助。</p>
<p>这是 <strong>MySQL数据库性能优化专题 </strong>系列的第一篇文章：<a href="http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter">MySQL 数据库性能优化之缓存参数优化</a></p>
<p>数据库属于 IO 密集型的应用程序，其主要职责就是数据的管理及存储工作。而我们知道，从内存中读取一个数据库的时间是微秒级别，而从一块普通硬盘上读取一个IO是在毫秒级别，二者相差3个数量级。所以，要优化数据库，首先第一步需要优化的就是 IO，尽可能将磁盘IO转化为内存IO。<strong><em>本文先从 MySQL 数据库IO相关参数（缓存参数）的角度来看看可以通过哪些参数进行IO优化</em></strong>：</p>
<ul>
<li><strong>query_cache_size/query_cache_type （global）</strong></li>
<p>Query cache 作用于整个 MySQL Instance，主要用来缓存 MySQL 中的 ResultSet，也就是一条SQL语句执行的结果集，所以仅仅只能针对select语句。当我们打开了 Query Cache 功能，MySQL在接受到一条select语句的请求后，如果该语句满足Query Cache的要求（未显式说明不允许使用Query Cache，或者已经显式申明需要使用Query Cache），MySQL 会直接根据预先设定好的HASH算法将接受到的select语句以字符串方式进行hash，然后到Query Cache 中直接查找是否已经缓存。也就是说，如果已经在缓存中，该select请求就会直接将数据返回，从而省略了后面所有的步骤（如 SQL语句的解析，优化器优化以及向存储引擎请求数据等），极大的提高性能。</p>
<p>当然，Query Cache 也有一个致命的缺陷，那就是当某个表的数据有任何任何变化，都会导致所有引用了该表的select语句在Query Cache 中的缓存数据失效。所以，当我们的数据变化非常频繁的情况下，使用Query Cache 可能会得不偿失。</p>
<p>Query Cache的使用需要多个参数配合，其中最为关键的是 query_cache_size 和 query_cache_type ，前者设置用于缓存 ResultSet 的内存大小，后者设置在何场景下使用 Query Cache。在以往的经验来看，如果不是用来缓存基本不变的数据的MySQL数据库，query_cache_size 一般 256MB 是一个比较合适的大小。当然，这可以通过计算Query Cache的命中率（Qcache_hits/(Qcache_hits+Qcache_inserts)*100)）来进行调整。query_cache_type可以设置为0(OFF)，1(ON)或者2(DEMOND)，分别表示完全不使用query cache，除显式要求不使用query cache（使用sql_no_cache）之外的所有的select都使用query cache，只有显示要求才使用query cache（使用sql_cache）。</p>
<li><strong>binlog_cache_size （global）</strong></li>
<p>Binlog  Cache 用于在打开了二进制日志（binlog）记录功能的环境，是 MySQL 用来提高binlog的记录效率而设计的一个用于短时间内临时缓存binlog数据的内存区域。</p>
<p>一般来说，如果我们的数据库中没有什么大事务，写入也不是特别频繁，2MB～4MB是一个合适的选择。但是如果我们的数据库大事务较多，写入量比较大，可与适当调高binlog_cache_size。同时，我们可以通过binlog_cache_use 以及 binlog_cache_disk_use来分析设置的binlog_cache_size是否足够，是否有大量的binlog_cache由于内存大小不够而使用临时文件（binlog_cache_disk_use）来缓存了。</p>
<li><strong>key_buffer_size （global）</strong></li>
<p>Key Buffer 可能是大家最为熟悉的一个 MySQL 缓存参数了，尤其是在 MySQL 没有更换默认存储引擎的时候，很多朋友可能会发现，默认的 MySQL 配置文件中设置最大的一个内存参数就是这个参数了。key_buffer_size 参数用来设置用于缓存 MyISAM存储引擎中索引文件的内存区域大小。如果我们有足够的内存，这个缓存区域最好是能够存放下我们所有的 MyISAM 引擎表的所有索引，以尽可能提高性能。</p>
<p>此外，当我们在使用MyISAM 存储的时候有一个及其重要的点需要注意，由于 MyISAM 引擎的特性限制了他仅仅只会缓存索引块到内存中，而不会缓存表数据库块。所以，我们的 SQL 一定要尽可能让过滤条件都在索引中，以便让缓存帮助我们提高查询效率。</p>
<li><strong>bulk_insert_buffer_size （thread）</strong></li>
<p>和key_buffer_size一样，这个参数同样也仅作用于使用 MyISAM存储引擎，用来缓存批量插入数据的时候临时缓存写入数据。当我们使用如下几种数据写入语句的时候，会使用这个内存区域来缓存批量结构的数据以帮助批量写入数据文件：</p>
<p>insert &#8230; select &#8230;<br />
insert &#8230; values (&#8230;) ,(&#8230;),(&#8230;)&#8230;<br />
load data infile&#8230; into&#8230; (非空表)</p>
<li><strong>innodb_buffer_pool_size（global）</strong></li>
<p>当我们使用InnoDB存储引擎的时候，innodb_buffer_pool_size 参数可能是影响我们性能的最为关键的一个参数了，他用来设置用于缓存 InnoDB 索引及数据块的内存区域大小，类似于 MyISAM 存储引擎的 key_buffer_size 参数，当然，可能更像是 Oracle 的 db_cache_size。简单来说，当我们操作一个 InnoDB 表的时候，返回的所有数据或者去数据过程中用到的任何一个索引块，都会在这个内存区域中走一遭。</p>
<p>和key_buffer_size 对于 MyISAM 引擎一样，innodb_buffer_pool_size 设置了 InnoDB 存储引擎需求最大的一块内存区域的大小，直接关系到 InnoDB存储引擎的性能，所以如果我们有足够的内存，尽可将该参数设置到足够打，将尽可能多的 InnoDB 的索引及数据都放入到该缓存区域中，直至全部。</p>
<p>我们可以通过 (Innodb_buffer_pool_read_requests – Innodb_buffer_pool_reads) / Innodb_buffer_pool_read_requests * 100% 计算缓存命中率，并根据命中率来调整 innodb_buffer_pool_size 参数大小进行优化。</p>
<li><strong>innodb_additional_mem_pool_size（global）</strong></li>
<p>这个参数我们平时调整的可能不是太多，很多人都使用了默认值，可能很多人都不是太熟悉这个参数的作用。innodb_additional_mem_pool_size 设置了InnoDB存储引擎用来存放数据字典信息以及一些内部数据结构的内存空间大小，所以当我们一个MySQL Instance中的数据库对象非常多的时候，是需要适当调整该参数的大小以确保所有数据都能存放在内存中提高访问效率的。</p>
<p>这个参数大小是否足够还是比较容易知道的，因为当过小的时候，MySQL 会记录 Warning 信息到数据库的 error log 中，这时候你就知道该调整这个参数大小了。</p>
<li><strong>innodb_log_buffer_size （global）</strong></li>
<p>这是 InnoDB 存储引擎的事务日志所使用的缓冲区。类似于 Binlog Buffer，InnoDB 在写事务日志的时候，为了提高性能，也是先将信息写入 Innofb Log Buffer 中，当满足 innodb_flush_log_trx_commit 参数所设置的相应条件（或者日志缓冲区写满）之后，才会将日志写到文件（或者同步到磁盘）中。可以通过 innodb_log_buffer_size 参数设置其可以使用的最大内存空间。<br />
注：innodb_flush_log_trx_commit 参数对 InnoDB Log 的写入性能有非常关键的影响。该参数可以设置为0，1，2，解释如下：</p>
<p>0：log buffer中的数据将以每秒一次的频率写入到log file中，且同时会进行文件系统到磁盘的同步操作，但是每个事务的commit并不会触发任何log buffer 到log file的刷新或者文件系统到磁盘的刷新操作；<br />
1：在每次事务提交的时候将log buffer 中的数据都会写入到log file，同时也会触发文件系统到磁盘的同步；<br />
2：事务提交会触发log buffer 到log file的刷新，但并不会触发磁盘文件系统到磁盘的同步。此外，每秒会有一次文件系统到磁盘同步操作。</p>
<p>此外，MySQL文档中还提到，这几种设置中的每秒同步一次的机制，可能并不会完全确保非常准确的每秒就一定会发生同步，还取决于进程调度的问题。实际上，InnoDB 能否真正满足此参数所设置值代表的意义正常 Recovery 还是受到了不同 OS 下文件系统以及磁盘本身的限制，可能有些时候在并没有真正完成磁盘同步的情况下也会告诉 mysqld 已经完成了磁盘同步。</p>
<li><strong>innodb_max_dirty_pages_pct （global）</strong></li>
<p>这个参数和上面的各个参数不同，他不是用来设置用于缓存某种数据的内存大小的一个参数，而是用来控制在 InnoDB Buffer Pool 中可以不用写入数据文件中的Dirty Page 的比例（已经被修但还没有从内存中写入到数据文件的脏数据）。这个比例值越大，从内存到磁盘的写入操作就会相对减少，所以能够一定程度下减少写入操作的磁盘IO。</p>
<p>但是，如果这个比例值过大，当数据库 Crash 之后重启的时间可能就会很长，因为会有大量的事务数据需要从日志文件恢复出来写入数据文件中。同时，过大的比例值同时可能也会造成在达到比例设定上限后的 flush 操作“过猛”而导致性能波动很大。</ul>
<div>上面这几个参数是 MySQL 中为了减少磁盘物理IO而设计的主要参数，对 MySQL 的性能起到了至关重要的作用。</div>
<div></div>
<div>&#8212;EOF&#8212;</div>
<div></div>
<div>按照 <a rel="external nofollow" href="http://heylinux.com/">mcsrainbow</a> 朋友的要求，这里列一下根据以往经验得到的相关参数的建议值：</div>
<div>
<ul>
<li>query_cache_type : 如果全部使用innodb存储引擎，建议为0，如果使用MyISAM 存储引擎，建议为2，同时在SQL语句中显式控制是否是哟你gquery cache</li>
<li>query_cache_size: 根据 命中率（Qcache_hits/(Qcache_hits+Qcache_inserts)*100)）进行调整，一般不建议太大，256MB可能已经差不多了，大型的配置型静态数据可适当调大</li>
<li>binlog_cache_size: 一般环境2MB～4MB是一个合适的选择，事务较大且写入频繁的数据库环境可以适当调大，但不建议超过32MB</li>
<li>key_buffer_size: 如果不使用MyISAM存储引擎，16MB足以，用来缓存一些系统表信息等。如果使用 MyISAM存储引擎，在内存允许的情况下，尽可能将所有索引放入内存，简单来说就是“越大越好”</li>
<li>bulk_insert_buffer_size: 如果经常性的需要使用批量插入的特殊语句（上面有说明）来插入数据，可以适当调大该参数至16MB～32MB，不建议继续增大，某人8MB</li>
<li>innodb_buffer_pool_size: 如果不使用InnoDB存储引擎，可以不用调整这个参数，如果需要使用，在内存允许的情况下，尽可能将所有的InnoDB数据文件存放如内存中，同样将但来说也是“越大越好”</li>
<li>innodb_additional_mem_pool_size: 一般的数据库建议调整到8MB～16MB，如果表特别多，可以调整到32MB，可以根据error log中的信息判断是否需要增大</li>
<li>innodb_log_buffer_size: 默认是1MB，系的如频繁的系统可适当增大至4MB～8MB。当然如上面介绍所说，这个参数实际上还和另外的flush参数相关。一般来说不建议超过32MB</li>
<li>innodb_max_dirty_pages_pct: 根据以往的经验，重启恢复的数据如果要超过1GB的话，启动速度会比较慢，几乎难以接受，所以建议不大于 1GB/innodb_buffer_pool_size(GB)*100 这个值。当然，如果你能够忍受启动时间比较长，而且希望尽量减少内存至磁盘的flush，可以将这个值调整到90，但不建议超过90</li>
</ul>
</div>
<p><em>注：以上取值范围仅仅只是我的根据以往遇到的数据库场景所得到的一些优化经验值，并不一定适用于所有场景，所以在实际优化过程中还需要大家自己不断的调整分析，也欢迎大家随时通过 Mail 与我联系沟通交流优化或者是架构方面的技术，一起探讨相互学习。</em></p>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter">http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">2012DTCC – 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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter">
                        <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?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">MySQL 数据库性能优化之SQL优化</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" 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><img src="http://www1.feedsky.com/t1/628286872/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/O62dLlYYwi3-v-7v_ZfmuLA-0bg/0/da"><img src="http://feedads.g.doubleclick.net/~a/O62dLlYYwi3-v-7v_ZfmuLA-0bg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/O62dLlYYwi3-v-7v_ZfmuLA-0bg/1/da"><img src="http://feedads.g.doubleclick.net/~a/O62dLlYYwi3-v-7v_ZfmuLA-0bg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/UBrCt54vqLw" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter/feed</wfw:commentRss><slash:comments>13</slash:comments><description>在平时被问及最多的问题就是关于 MySQL 数据库性能优化方面的问题，所以最近打算写一个MySQL数据库性能优化方面的系列文章，希望对初中级 MySQL DBA 以及其他对 MySQL 性能优化感兴趣的朋友们有所帮助。
这是 MySQL数据库性能优化专题 系列的第一篇文章：MySQL 数据库性能优化之缓存参数优化
数据库属于 IO 密集型的应用程序，其主要职责就是数据的管理及存储工作。而我们知道，从内存中读取一个数据库的时间是微秒级别，而从一块普通硬盘上读取一个IO是在毫秒级别，二者相差3个数量级。所以，要优化数据库，首先第一步需要优化的就是 IO，尽可能将磁盘IO转化为内存IO。本文先从 MySQL 数据库IO相关参数（缓存参数）的角度来看看可以通过哪些参数进行IO优化：

query_cache_size/query_cache_type （global）
Query cache 作用于整个 MySQL Instance，主要用来缓存 MySQL 中的 ResultSet，也就是一条SQL语句执行的结果集，所以仅仅只能针对select语句。当我们打开了 Query Cache 功能，MySQL在接受到一条select语句的请求后，如果该语句满足Query Cache的要求（未显式说明不允许使用Query Cache，或者已经显式申明需要使用Query Cache），MySQL 会直接根据预先设定好的HASH算法将接受到的select语句以字符串方式进行hash，然后到Query Cache 中直接查找是否已经缓存。也就是说，如果已经在缓存中，该select请求就会直接将数据返回，从而省略了后面所有的步骤（如 SQL语句的解析，优化器优化以及向存储引擎请求数据等），极大的提高性能。
当然，Query Cache 也有一个致命的缺陷，那就是当某个表的数据有任何任何变化，都会导致所有引用了该表的select语句在Query Cache 中的缓存数据失效。所以，当我们的数据变化非常频繁的情况下，使用Query Cache 可能会得不偿失。
Query Cache的使用需要多个参数配合，其中最为关键的是 query_cache_size 和 query_cache_type ，前者设置用于缓存 ResultSet 的内存大小，后者设置在何场景下使用 Query Cache。在以往的经验来看，如果不是用来缓存基本不变的数据的MySQL数据库，query_cache_size 一般 256MB 是一个比较合适的大小。当然，这可以通过计算Query Cache的命中率（Qcache_hits/(Qcache_hits+Qcache_inserts)*100)）来进行调整。query_cache_type可以设置为0(OFF)，1(ON)或者2(DEMOND)，分别表示完全不使用query cache，除显式要求不使用query cache（使用sql_no_cache）之外的所有的select都使用query cache，只有显示要求才使用query [...]&lt;table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-index&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之索引优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;"&gt;
                    &lt;img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif"&gt;
                    &lt;a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-sql&amp;from=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-perfornamce-tuning-cache-parameter"&gt;
                        &lt;font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;"&gt;MySQL 数据库性能优化之SQL优化&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286872/sky000/feedsky/s.gif?r=http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>MySQL数据库性能优化专题</category><category>MySQL</category><category>DataBase</category><category>performance tuning</category><pubDate>Wed, 26 Oct 2011 12:17:12 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter#comments</comments><guid isPermaLink="false">http://isky000.com/?p=983</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286872/1222002</fs:itemid><feedburner:origLink>http://isky000.com/database/mysql-perfornamce-tuning-cache-parameter</feedburner:origLink></item><item><title>MySQL 优化资料推荐</title><link>http://feedproxy.google.com/~r/sky000/~3/aab6WX7kj4Y/good-performance-tuning-slide</link><content:encoded><![CDATA[<p>最近看到一个比较全面的MySQL优化的PPT，不敢独享，特放上来与大家分享。</p>
<p><span style="color: #0000ff;"><span style="color: #ff0000;">注：版权所有:</span> </span><strong><a href="http://www.blogger.com/profile/14180479977952026421" target="_blank">Yoshinori Matsunobu</a></strong></p>
<div style="width:595px" id="__ss_7614520"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/matsunobu/linux-and-hw-optimizations-for-mysql-7614520" title="Linux and H/W optimizations for MySQL" target="_blank">Linux and H/W optimizations for MySQL</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/7614520" width="595" height="497" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/matsunobu" target="_blank">Yoshinori Matsunobu</a> </div>
</p></div>
<hr />作者： <a href="http://isky000.com">Sky.Jian</a> &nbsp;发布在：<a href="http://isky000.com">iSky000.com</a> &nbsp;欢迎&nbsp;<a href="http://feed.feedsky.com/sky000">订阅本站Feed</a><br />Copyright &copy; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/">版权声明</a> <br />链接：<a href="http://isky000.com/study-reading/good-performance-tuning-slide">http://isky000.com/study-reading/good-performance-tuning-slide</a><br />Hosted On <a href="http://www.dreamhost.com/rewards.cgi?imysqler">Dreamhost</a>,折扣码 iMySQLer )</small><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="2012DTCC – MySQL性能调优最佳实践" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">2012DTCC – MySQL性能调优最佳实践</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="MySQL数据库性能优化之存储引擎选择" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">MySQL数据库性能优化之存储引擎选择</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="《MySQL性能调优与架构设计》正式发售" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Ffirst-sale&from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/05/16239942.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">《MySQL性能调优与架构设计》正式发售</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="MySQL5.1 Generally Available (GA) release for production use" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql51_ga_release&from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/05/16240311.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">MySQL5.1 Generally Available (GA) release for production use</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" 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><img src="http://www1.feedsky.com/t1/628286873/sky000/feedsky/s.gif?r=http://isky000.com/study-reading/good-performance-tuning-slide" border="0" height="0" width="0" style="position:absolute" />
<p><a href="http://feedads.g.doubleclick.net/~a/M1w-IBkhmGbsb7nYF5rPnaXrIC0/0/da"><img src="http://feedads.g.doubleclick.net/~a/M1w-IBkhmGbsb7nYF5rPnaXrIC0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/M1w-IBkhmGbsb7nYF5rPnaXrIC0/1/da"><img src="http://feedads.g.doubleclick.net/~a/M1w-IBkhmGbsb7nYF5rPnaXrIC0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sky000/~4/aab6WX7kj4Y" height="1" width="1"/>]]></content:encoded><wfw:commentRss>http://isky000.com/study-reading/good-performance-tuning-slide/feed</wfw:commentRss><slash:comments>2</slash:comments><description>最近看到一个比较全面的MySQL优化的PPT，不敢独享，特放上来与大家分享。
注：版权所有: Yoshinori Matsunobu
 Linux and H/W optimizations for MySQL 
 View more presentations from Yoshinori Matsunobu 

作者： Sky.Jian &amp;#160;发布在：iSky000.com &amp;#160;欢迎&amp;#160;订阅本站FeedCopyright &amp;#169; 2004-2008， 可以任意转载, 但转载时务必以超链接形式标明文章原始出处 和 作者信息 及 版权声明 链接：http://isky000.com/study-reading/good-performance-tuning-slideHosted On Dreamhost,折扣码 iMySQLer )&lt;table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;"&gt;
    
    &lt;tr&gt;
        &lt;td colspan="4"&gt;&lt;b&gt;&lt;font size="-1"  style="display: block !important; padding: 20px 0 5px !important;"&gt;您可能也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;"&gt;
                    &lt;a target="_blank" title="2012DTCC – MySQL性能调优最佳实践" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2F2012dtcc-mysql-performance-tuning-practise&amp;from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide"&gt;
                        &lt;img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /&gt;&lt;br /&gt;
                        &lt;font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;"&gt;2012DTCC – MySQL性能调优最佳实践&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"&gt;
                    &lt;a target="_blank" title="MySQL数据库性能优化之存储引擎选择" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql-performance-tuning-storage-engine&amp;from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide"&gt;
                        &lt;img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /&gt;&lt;br /&gt;
                        &lt;font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;"&gt;MySQL数据库性能优化之存储引擎选择&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"&gt;
                    &lt;a target="_blank" title="《MySQL性能调优与架构设计》正式发售" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fmysql-performance-tuning-and-architecture%2Ffirst-sale&amp;from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide"&gt;
                        &lt;img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/05/16239942.png" width="96px" height="96px" /&gt;&lt;br /&gt;
                        &lt;font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;"&gt;《MySQL性能调优与架构设计》正式发售&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;"&gt;
                    &lt;a target="_blank" title="MySQL5.1 Generally Available (GA) release for production use" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fisky000.com%2Fdatabase%2Fmysql51_ga_release&amp;from=http%3A%2F%2Fisky000.com%2Fstudy-reading%2Fgood-performance-tuning-slide"&gt;
                        &lt;img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/05/16240311.jpg" width="96px" height="96px" /&gt;&lt;br /&gt;
                        &lt;font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;"&gt;MySQL5.1 Generally Available (GA) release for production use&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan="4" align="right"&gt;
            &lt;a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件"&gt;
                &lt;font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;"&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://www1.feedsky.com/t1/628286873/sky000/feedsky/s.gif?r=http://isky000.com/study-reading/good-performance-tuning-slide" border="0" height="0" width="0" style="position:absolute" /&gt;</description><category>Study &amp; Reading</category><pubDate>Mon, 17 Oct 2011 14:05:59 +0800</pubDate><author>朝阳</author><comments>http://isky000.com/study-reading/good-performance-tuning-slide#comments</comments><guid isPermaLink="false">http://isky000.com/?p=977</guid><dc:creator>朝阳</dc:creator><fs:srclink>http://isky000.com/study-reading/good-performance-tuning-slide</fs:srclink><fs:srcfeed>http://iSky000.com/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/sky000/~8105763/628286873/1222002</fs:itemid><feedburner:origLink>http://isky000.com/study-reading/good-performance-tuning-slide</feedburner:origLink></item></channel></rss>

