??xml version="1.0" encoding="utf-8" standalone="yes"?>国产Av激情久久无码天堂,久久久国产视频,2021国内精品久久久久久影院http://www.shnenglu.com/wanghaiguang/category/20408.html逆水行舟Q不q则退zh-cnFri, 29 Nov 2013 08:55:25 GMTFri, 29 Nov 2013 08:55:25 GMT60MySQL性能优化的最?0+条经?/title><link>http://www.shnenglu.com/wanghaiguang/archive/2013/11/28/204490.html</link><dc:creator>王v?/dc:creator><author>王v?/author><pubDate>Thu, 28 Nov 2013 03:40:00 GMT</pubDate><guid>http://www.shnenglu.com/wanghaiguang/archive/2013/11/28/204490.html</guid><wfw:comment>http://www.shnenglu.com/wanghaiguang/comments/204490.html</wfw:comment><comments>http://www.shnenglu.com/wanghaiguang/archive/2013/11/28/204490.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/wanghaiguang/comments/commentRss/204490.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/wanghaiguang/services/trackbacks/204490.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">今天Q数据库的操作越来越成ؓ(f)整个应用的性能瓉?jin),q点对于Web应用其明显。关于数据库的性能Q这q不只是DBA才需要担?j)的事,而这更是我们E序员需要去x(chng)的事情。当我们去设计数据库表结构,Ҏ(gu)作数据库Ӟ其是查表时的SQL语句Q,我们都需要注意数据操作的性能。这里,我们不会(x)讲过多的SQL语句的优化,而只是针对MySQLq一Web应用最多的数据库。希望下面的q些优化技巧对你有用?/p><h4>1. 为查询缓存(sh)化你的查?/h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">大多数的MySQL服务器都开启了(jin)查询~存。这是提高性最有效的方法之一Q而且q是被MySQL的数据库引擎处理的。当有很多相同的查询被执行了(jin)多次的时候,q些查询l果?x)被攑ֈ一个缓存(sh)Q这P后箋(hu)的相同的查询׃用操作表而直接访问缓存结果了(jin)?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">q里最主要的问题是Q对于程序员来说Q这个事情是很容易被忽略的。因为,我们某些查询语句?x)让MySQL不用缓存。请看下面的CZQ?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #339966;">//</span><span style="color: #339966;"> 查询~存?sh)开?/span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> username </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> signup_date </span><span style="color: #808080; ">>=</span><span style="color: #000000; "> CURDATE()");<br /> <br /></span><span style="color: #339966;">//</span><span style="color: #339966;"> 开启查询缓?/span><span style="color: #000000; "><br />$today </span><span style="color: #808080; ">=</span><span style="color: #000000; "> date("Y</span><span style="color: #808080; ">-</span><span style="color: #000000; ">m</span><span style="color: #808080; ">-</span><span style="color: #000000; ">d");<br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> username </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> signup_date </span><span style="color: #808080; ">>=</span><span style="color: #000000; "> </span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">$today</span><span style="color: #FF0000; ">'</span><span style="color: #000000; ">");<br /></span></div></p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">上面两条SQL语句的差别就?CURDATE() QMySQL的查询缓存对q个函数不v作用。所以,?NOW() ?RAND() 或是其它的诸如此cȝSQL函数都不?x)开启查询缓存,因ؓ(f)q些函数的返回是?x)不定的易变的。所以,你所需要的是用一个变量来代替MySQL的函敎ͼ从而开启缓存?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"></p><h4>2. EXPLAIN 你的 SELECT 查询</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">使用 <a target="_blank" style="color: #2970a6; text-decoration: none;">EXPLAIN</a> 关键字可以让你知道MySQL是如何处理你的SQL语句的。这可以帮你分析你的查询语句或是表结构的性能瓉?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">EXPLAIN 的查询结果还?sh)(x)告诉你你的索引主键被如何利用的Q你的数据表是如何被搜烦(ch)和排序的……{等Q等{?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">?xi)一个你的SELECT语句Q推荐挑(xi)选那个最复杂的,有多表联接的Q,把关键字EXPLAIN加到前面。你可以使用phpmyadmin来做q个事。然后,你会(x)看到一张表根{下面的q个CZ中,我们忘记加上?jin)group_id索引Qƈ且有表联接:(x)</p><div style="margin: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><img src="http://www.shnenglu.com/images/cppblog_com/wanghaiguang/unoptimized_explain.jpg" width="540" height="242" alt="" /></div><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">当我们ؓ(f) group_id 字段加上索引后:(x)</p><div style="margin: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><img src="http://www.shnenglu.com/images/cppblog_com/wanghaiguang/optimized_explain.jpg" width="540" height="280" alt="" /></div><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">我们可以看到Q前一个结果显C搜索了(jin) 7883 行,而后一个只是搜索了(jin)两个表的 9 ?16 行。查看rows列可以让我们扑ֈ潜在的性能问题?/p><h4>3. 当只要一行数据时使用 LIMIT 1</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">当你查询表的有些时候,你已l知道结果只?x)有一条结果,但因Z可能需要去fetch游标Q或是你也许?x)去(g)查返回的记录数?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">在这U情况下Q加?LIMIT 1 可以增加性能。这样一PMySQL数据库引擎会(x)在找C条数据后停止搜烦(ch)Q而不是l往后查下一条符合记录的数据?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">下面的示例,只是Z(jin)找一下是否有“中国”的用P很明显,后面的会(x)比前面的更有效率。(h意,W一条中是Select *Q第二条是Select 1Q?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #339966;">//</span><span style="color: #339966;"> 没有效率的:(x)</span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> </span><span style="color: #808080; ">*</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> country </span><span style="color: #808080; ">=</span><span style="color: #000000; "> </span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">China</span><span style="color: #FF0000; ">'</span><span style="color: #000000; ">");<br /></span><span style="color: #0000FF; ">if</span><span style="color: #000000; "> (mysql_num_rows($r) </span><span style="color: #808080; ">></span><span style="color: #000000; "> </span><span style="color: #800000; font-weight: bold; ">0</span><span style="color: #000000; ">) {<br />    </span><span style="color: #339966;">//</span><span style="color: #000000; "> <img src="http://www.shnenglu.com/Images/dot.gif" alt="" /><br />}<br /> <br /></span><span style="color: #339966;">//</span><span style="color: #339966;"> 有效率的Q?/span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> </span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> country </span><span style="color: #808080; ">=</span><span style="color: #000000; "> </span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">China</span><span style="color: #FF0000; ">'</span><span style="color: #000000; "> LIMIT </span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">");<br /></span><span style="color: #0000FF; ">if</span><span style="color: #000000; "> (mysql_num_rows($r) </span><span style="color: #808080; ">></span><span style="color: #000000; "> </span><span style="color: #800000; font-weight: bold; ">0</span><span style="color: #000000; ">) {<br />    </span><span style="color: #339966;">//</span><span style="color: #000000; "> <img src="http://www.shnenglu.com/Images/dot.gif" alt="" /><br />}</span></div></p><h4>4. 为搜索字D徏索引</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">索引q不一定就是给主键或是唯一的字Dc(din)如果在你的表中Q有某个字段你总要?x)经常用来做搜?ch)Q那么,请ؓ(f)其徏立烦(ch)引吧?/p><div style="margin: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><img src="http://www.shnenglu.com/images/cppblog_com/wanghaiguang/search_index.jpg" width="580" height="225" alt="" /></div><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">从上图你可以看到那个搜烦(ch)字串 “last_name LIKE ‘a%’”Q一个是Z(jin)索引Q一个是没有索引Q性能差了(jin)4倍左叟?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">另外Q你应该也需要知道什么样的搜索是不能使用正常的烦(ch)引的。例如,当你需要在一大的文章中搜烦(ch)一个词Ӟ如:(x) “WHERE post_content LIKE ‘%apple%’”Q烦(ch)引可能是没有意义的。你可能需要?a target="_blank" style="color: #2970a6; text-decoration: none;">MySQL全文索引</a> 或是自己做一个烦(ch)引(比如_(d)(x)搜烦(ch)关键词或是Tag什么的Q?/p><h4>5. 在Join表的时候用相当类型的例,q将其烦(ch)?/h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">如果你的应用E序有很?JOIN 查询Q你应该认两个表中Join的字D|被徏q烦(ch)引的。这PMySQL内部?x)启动?f)你优化Join的SQL语句的机制?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">而且Q这些被用来Join的字D,应该是相同的cd的。例如:(x)如果你要?DECIMAL 字段和一?INT 字段Join在一PMySQL无法用它们的索引。对于那些STRINGcdQ还需要有相同的字W集才行。(两个表的字符集有可能不一P(j)<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #339966;">//</span><span style="color: #339966;"> 在state中查找company</span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> company_name </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> users<br />    </span><span style="color: #FF00FF; ">LEFT</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">JOIN</span><span style="color: #000000; "> companies </span><span style="color: #0000FF; ">ON</span><span style="color: #000000; "> (users.state </span><span style="color: #808080; ">=</span><span style="color: #000000; "> companies.state)<br />    </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> users.id </span><span style="color: #808080; ">=</span><span style="color: #000000; "> $</span><span style="color: #FF00FF; ">user_id</span><span style="color: #000000; ">");<br /> <br /></span><span style="color: #339966;">//</span><span style="color: #339966;"> 两个 state 字段应该是被索引的,而且应该是相当的cdQ相同的字符集?/span></div></p><h4>6. 千万不要 ORDER BY RAND()</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">x(chng)p回的数据行?随机?xi)一个数据?真不知道谁发明了(jin)q种用法Q但很多新手很喜Ƣ这L(fng)。但你确不了(jin)解这样做有多么可怕的性能问题?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">如果你真的想把返回的数据行打׃(jin)Q你有NU方法可以达到这个目的。这样用只让你的数据库的性能呈指数的下降。这里的问题是:(x)MySQL?x)不得不L行RAND()函数Q很耗CPU旉Q,而且q是Z(jin)每一行记录去记行Q然后再对其排序。就是你用?jin)Limit 1也无于事(因ؓ(f)要排序)(j)</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">下面的示例是随机?xi)一条记?/p><div style="margin: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #339966;">//</span><span style="color: #339966;"> 千万不要q样做:(x)</span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> username </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">ORDER</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">BY</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">RAND</span><span style="color: #000000; ">() LIMIT </span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">");<br /> <br /></span><span style="color: #339966;">//</span><span style="color: #339966;"> q要?x)更好?x)</span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">count</span><span style="color: #000000; ">(</span><span style="color: #808080; ">*</span><span style="color: #000000; ">) </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; ">");<br />$d </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_fetch_row($r);<br />$</span><span style="color: #FF00FF; ">rand</span><span style="color: #000000; "> </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mt_rand(</span><span style="color: #800000; font-weight: bold; ">0</span><span style="color: #000000; ">,$d</span><span style="color: #FF0000; ">[</span><span style="color: #FF0000; ">0</span><span style="color: #FF0000; ">]</span><span style="color: #000000; "> </span><span style="color: #808080; ">-</span><span style="color: #000000; "> </span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">);<br /> <br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> username </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> LIMIT $</span><span style="color: #FF00FF; ">rand</span><span style="color: #000000; ">, </span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">");</span></div></div><h4>7. 避免 SELECT *</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">从数据库里读?gu)多的数据Q那么查询就?x)变得越慢。ƈ且,如果你的数据库服务器和W(xu)EB服务器是两台独立的服务器的话Q这q(sh)(x)增加|络传输的负载?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">所以,你应该养成一个需要什么就取什么的好的?fn)惯?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #339966;">//</span><span style="color: #339966;"> 不推?/span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> </span><span style="color: #808080; ">*</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user_id</span><span style="color: #000000; "> </span><span style="color: #808080; ">=</span><span style="color: #000000; "> </span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">");<br />$d </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_fetch_assoc($r);<br />echo "Welcome {$d</span><span style="color: #FF0000; ">[</span><span style="color: #FF0000; ">'username'</span><span style="color: #FF0000; ">]</span><span style="color: #000000; ">}";<br /> <br /></span><span style="color: #339966;">//</span><span style="color: #339966;"> 推荐</span><span style="color: #000000; "><br />$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_query("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> username </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user_id</span><span style="color: #000000; "> </span><span style="color: #808080; ">=</span><span style="color: #000000; "> </span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">");<br />$d </span><span style="color: #808080; ">=</span><span style="color: #000000; "> mysql_fetch_assoc($r);<br />echo "Welcome {$d</span><span style="color: #FF0000; ">[</span><span style="color: #FF0000; ">'username'</span><span style="color: #FF0000; ">]</span><span style="color: #000000; ">}";</span></div></p><h4>8. 永远为每张表讄一个ID</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">我们应该为数据库里的每张表都讄一个ID做ؓ(f)其主键,而且最好的是一个INT型的Q推荐用UNSIGNEDQ,q设|上自动增加的AUTO_INCREMENT标志?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">q是你 users 表有一个主键叫 “email”的字D,你也别让它成Z键。?VARCHAR cd来当主键?x)用得性能下降。另外,在你的程序中Q你应该使用表的ID来构造你的数据结构?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">而且Q在MySQL数据引擎下,q有一些操作需要用主键,在这些情况下Q主键的性能和设|变得非帔R要,比如Q集,分区……</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">在这里,只有一个情冉|例外Q那是“兌?#8221;?#8220;外键”Q也是_(d)q个表的主键Q通过若干个别的表的主键构成。我们把q个情况叫做“外键”。比如:(x)有一?#8220;学生?#8221;有学生的IDQ有一?#8220;评?#8221;有课EIDQ那么,“成W?#8221;是“兌?#8221;?jin),其关联?jin)学生表和评表,在成l表中,学生ID和课EID?#8220;外键”其共同组成主键?/p><h4>9. 使用 ENUM 而不?VARCHAR</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><a target="_blank" style="color: #2970a6; text-decoration: none;">ENUM</a> cd是非常快和紧凑的。在实际上,其保存的?TINYINTQ但其外表上昄为字W串。这样一来,用这个字D|做一些选项列表变得相当的完?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">如果你有一个字D,比如“性别”Q?#8220;国家”Q?#8220;民族”Q?#8220;状?#8221;?#8220;部门”Q你知道q些字段的取值是有限而且固定的,那么Q你应该使用 ENUM 而不?VARCHAR?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">MySQL也有一?#8220;”Q见W十条)(j)告诉你怎么去重新组l你的表l构。当你有一?VARCHAR 字段Ӟq个?x)告诉你把其?gu) ENUM cd。?PROCEDURE ANALYSE() 你可以得到相关的?/p><h4>10. ?PROCEDURE ANALYSE() 取得</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><a target="_blank" style="color: #2970a6; text-decoration: none;">PROCEDURE ANALYSE()</a> ?x)?MySQL 帮你d析你的字D和其实际的数据Qƈ?x)给你一些有用的。只有表中有实际的数据,q些才会(x)变得有用Q因做一些大的决定是需要有数据作ؓ(f)基础的?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">例如Q如果你创徏?jin)一?INT 字段作ؓ(f)你的主键Q然而ƈ没有太多的数据,那么QPROCEDURE ANALYSE()?x)徏议你把这个字D늚cdҎ(gu) MEDIUMINT 。或是你使用?jin)一?VARCHAR 字段Q因为数据不多,你可能会(x)得到一个让你把它改?ENUM 的徏议。这些徏议,都是可能因ؓ(f)数据不够多,所以决{做得就不够准?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">在phpmyadmin里,你可以在查看表时Q点?“Propose table structure” 来查看这些徏?/p><div style="margin: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><img src="http://www.shnenglu.com/images/cppblog_com/wanghaiguang/suggestions.jpg" width="418" height="249" alt="" /></div><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">一定要注意Q这些只是徏议,只有当你的表里的数据来多Ӟq些才会(x)变得准确。一定要CQ你才是最l做军_的h?/p><h4>11. 可能的使用 NOT NULL</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">除非你有一个很特别的原因去使用 NULL |你应该L让你的字D保?NOT NULL。这看v来好像有点争议,请往下看?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">首先Q问问你自己“Empty”?#8220;NULL”有多大的区别Q如果是INTQ那是0和NULLQ?如果你觉得它们之间没有什么区别,那么你就不要使用NULL。(你知道吗Q在 Oracle 里,NULL ?Empty 的字W串是一L(fng)Q?</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">不要以ؓ(f) NULL 不需要空_(d)光要额外的I间Qƈ且,在你q行比较的时候,你的E序?x)更复杂?当然Q这里ƈ不是说你׃能用NULL?jin),现实情况是很复杂的,依然会(x)有些情况下Q你需要用NULL倹{?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">下面摘自MySQL自己的文档:(x)</p><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; background-image: url(http://coolshell.cn/wp-content/themes/inove/img/blockquote.gif); background-color: #f4f5f7; border: 1px dashed #cccccc; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;"><p style="margin: 0px 0px 10px; padding: 0px;">“NULL columns require additional space in the row to record whether their values are NULL. For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.”</p></blockquote><h4>12. Prepared Statements</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">Prepared Statements很像存储q程Q是一U运行在后台的SQL语句集合Q我们可以从使用 prepared statements 获得很多好处Q无论是性能问题q是安全问题?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">Prepared Statements 可以(g)查一些你l定好的变量Q这样可以保护你的程序不?x)受?#8220;SQL注入?#8221;d。当?dng)你也可以手动地检查你的这些变量,然而,手动的检查容易出问题Q而且很经怼(x)被程序员忘(sh)(jin)。当我们使用一些framework或是ORM的时候,q样的问题(sh)(x)好一些?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">在性能斚wQ当一个相同的查询被用多ơ的时候,q会(x)Z带来可观的性能优势。你可以l这些Prepared Statements定义一些参敎ͼ而MySQL只会(x)解析一ơ?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">虽然最新版本的MySQL在传输P(yng)repared Statements是用二q制形势Q所以这?x)得网l传输非常有效率?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">当然Q也有一些情况下Q我们需要避免用Prepared StatementsQ因为其不支持查询缓存。但据说版本5.1后支持了(jin)?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">在PHP中要使用prepared statementsQ你可以查看其用手册:(x)<a target="_blank" style="color: #2970a6; text-decoration: none;">mysqli 扩展</a> 或是使用数据库抽象层Q如Q?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">PDO</a>.<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #339966;">//</span><span style="color: #339966;"> 创徏 prepared statement</span><span style="color: #000000; "><br /></span><span style="color: #0000FF; ">if</span><span style="color: #000000; "> ($stmt </span><span style="color: #808080; ">=</span><span style="color: #000000; "> $mysqli</span><span style="color: #808080; ">-></span><span style="color: #0000FF; ">prepare</span><span style="color: #000000; ">("</span><span style="color: #0000FF; ">SELECT</span><span style="color: #000000; "> username </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> state</span><span style="color: #808080; ">=</span><span style="color: #000000; ">?")) {<br /> <br /></span><span style="color: #339966;">    </span><span style="color: #339966;">//</span><span style="color: #339966;"> l定参数</span><span style="color: #000000; "><br />    $stmt</span><span style="color: #808080; ">-></span><span style="color: #000000; ">bind_param("s", $state);<br /> <br />    </span><span style="color: #339966;">//</span><span style="color: #339966;"> 执行</span><span style="color: #000000; "><br />    $stmt</span><span style="color: #808080; ">-></span><span style="color: #0000FF; ">execute</span><span style="color: #000000; ">();<br /> <br /></span><span style="color: #339966;">    </span><span style="color: #339966;">//</span><span style="color: #339966;"> l定l果</span><span style="color: #000000; "><br />    $stmt</span><span style="color: #808080; ">-></span><span style="color: #000000; ">bind_result($username);<br /> <br />    </span><span style="color: #339966;">//</span><span style="color: #339966;"> Ud游标</span><span style="color: #000000; "><br />    $stmt</span><span style="color: #808080; ">-></span><span style="color: #0000FF; ">fetch</span><span style="color: #000000; ">();<br /> <br />    printf("</span><span style="color: #808080; ">%</span><span style="color: #000000; ">s </span><span style="color: #0000FF; ">is</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">from</span><span style="color: #000000; "> </span><span style="color: #808080; ">%</span><span style="color: #000000; ">s\n", $username, $state);<br /> <br />    $stmt</span><span style="color: #808080; ">-></span><span style="color: #0000FF; ">close</span><span style="color: #000000; ">();<br />}</span></div></p><h4>13. 无缓冲的查询</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">正常的情况下Q当你在当你在你的脚本中执行一个SQL语句的时候,你的E序?x)停在那里直到没q个SQL语句q回Q然后你的程序再往下l执行。你可以使用无缓冲查询来改变q个行ؓ(f)?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">关于q个事情Q在PHP的文档中有一个非怸错的说明Q?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">mysql_unbuffered_query()</a> 函数Q?/p><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; background-image: url(http://coolshell.cn/wp-content/themes/inove/img/blockquote.gif); background-color: #f4f5f7; border: 1px dashed #cccccc; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;"><p style="margin: 0px 0px 10px; padding: 0px;">“mysql_unbuffered_query() sends the SQL query query to MySQL without automatically fetching and buffering the result rows as mysql_query() does. This saves a considerable amount of memory with SQL queries that produce large result sets, and you can start working on the result set immediately after the first row has been retrieved as you don’t have to wait until the complete SQL query has been performed.”</p></blockquote><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">上面那句话翻译过来是_(d)mysql_unbuffered_query() 发送一个SQL语句到MySQL而ƈ不像mysql_query()一样去自动fethch和缓存结果。这?x)相当节U很多可观的内存Q尤其是那些?x)生大量结果的查询语句Qƈ且,你不需要等到所有的l果都返回,只需要第一行数据返回的时候,你就可以开始马上开始工作于查询l果?jin)?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">然而,q会(x)有一些限制。因Z要么把所有行都读赎ͼ或是你要在进行下一ơ的查询前调?a target="_blank" style="color: #2970a6; text-decoration: none;">mysql_free_result()</a> 清除l果。而且Q?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">mysql_num_rows()</a> ?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">mysql_data_seek()</a> 无法用。所以,是否使用无缓冲的查询你需要仔l考虑?/p><h4>14. 把IP地址存成 UNSIGNED INT</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">很多E序员都?x)创Z?VARCHAR(15) 字段来存攑֭W串形式的IP而不是整形的IP。如果你用整形来存放Q只需?个字节,q且你可以有定长的字Dc(din)而且Q这?x)?f)你带来查询上的优势,其是当你需要用这L(fng)WHERE条gQIP between ip1 and ip2?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">我们必需要用UNSIGNED INTQ因?IP地址?x)用整?2位的无符h形?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">而你的查询,你可以?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">INET_ATON()</a> 来把一个字W串IP转成一个整形,q?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">INET_NTOA()</a> 把一个整形{成一个字W串IP。在PHP中,也有q样的函?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">ip2long()</a> ?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">long2ip()</a>?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">$r </span><span style="color: #808080; ">=</span><span style="color: #000000; "> "</span><span style="color: #0000FF; ">UPDATE</span><span style="color: #000000; "> users </span><span style="color: #0000FF; ">SET</span><span style="color: #000000; "> ip </span><span style="color: #808080; ">=</span><span style="color: #000000; "> INET_ATON(</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">{$_SERVER[</span><span style="color: #FF0000; ">'</span><span style="color: #000000; ">REMOTE_ADDR</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">]}</span><span style="color: #FF0000; ">'</span><span style="color: #000000; ">) </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> </span><span style="color: #FF00FF; ">user_id</span><span style="color: #000000; "> </span><span style="color: #808080; ">=</span><span style="color: #000000; "> $</span><span style="color: #FF00FF; ">user_id</span><span style="color: #000000; ">";</span></div></p><h4>15. 固定长度的表?x)更?/h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">如果表中的所有字D都?#8220;固定长度”的,整个表会(x)被认为是 <a target="_blank" style="color: #2970a6; text-decoration: none;">“static” ?“fixed-length”</a>?例如Q表中没有如下类型的字段Q?VARCHARQTEXTQBLOB。只要你包括?jin)其中一个这些字D,那么q个表就不是“固定长度?rn)态表”?jin),q样QMySQL 引擎?x)用另一U方法来处理?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">固定长度的表?x)提高性能Q因为MySQL搜寻得会(x)更快一些,因ؓ(f)q些固定的长度是很容易计下一个数据的偏移量的Q所以读取的自然也会(x)很快。而如果字D不是定长的Q那么,每一ơ要找下一条的话,需要程序找C键?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">q且Q固定长度的表也更容易被~存和重建。不q,唯一的副作用是,固定长度的字D会(x)费一些空_(d)因ؓ(f)定长的字D|Z用不用,他都是要分配那么多的I间?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">使用“垂直分割”技术(见下一条)(j)Q你可以分割你的表成Z个一个是定长的,一个则是不定长的?/p><h4>16. 垂直分割</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">“垂直分割”是一U把数据库中的表按列变成几张表的Ҏ(gu)Q这样可以降低表的复杂度和字D늚数目Q从而达C化的目的。(以前Q在银行做过目Q见q一张表?00多个字段Q很恐怖)(j)</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><strong>CZ一</strong>Q在Users表中有一个字D|家庭地址Q这个字D|可选字D,相比P而且你在数据库操作的时候除?jin)个Z息外Q你q不需要经常读取或是改写这个字Dc(din)那么,Z么不把他攑ֈ另外一张表中呢Q?q样?x)让你的表有更好的性能Q大家想x(chng)不是Q大量的时候,我对于用戯来说Q只有用户IDQ用户名Q口令,用户角色{会(x)被经怋用。小一点的表L?x)有好的性能?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><strong>CZ?/strong>Q?你有一个叫 “last_login” 的字D,它会(x)在每ơ用L(fng)录时被更新。但是,每次更新时会(x)D该表的查询缓存被清空。所以,你可以把q个字段攑ֈ另一个表中,q样׃?x)?jing)响你对用户IDQ用户名Q用戯色的不停地读取了(jin)Q因为查询缓存(sh)(x)帮你增加很多性能?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">另外Q你需要注意的是,q些被分出去的字D|形成的表Q你不会(x)l常性地去Join他们Q不然的话,q样的性能?x)比不分割时q要差,而且Q会(x)是极数的下降?/p><h4>17. 拆分大的 DELETE ?INSERT 语句</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">如果你需要在一个在U的|站上去执行一个大?DELETE ?INSERT 查询Q你需要非常小?j),要避免你的操作让你的整个|站停止相应。因两个操作是会(x)锁表的,表一锁住?jin),别的操作都进不来了(jin)?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">Apache ?x)有很多的子q程或线E。所以,其工作v来相当有效率Q而我们的服务器也不希望有太多的子q程Q线E和数据库链接,q是极大的占服务器资源的事情Q尤其是内存?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">如果你把你的表锁上一D|_(d)比如30U钟Q那么对于一个有很高讉K量的站点来说Q这30U所U篏的访问进E?U程Q数据库链接Q打开的文件数Q可能不仅仅?x)让你泊WEB服务CrashQ还可能?x)让你的整台服务器马上掛了(jin)?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">所以,如果你有一个大的处理,你定你一定把其拆分,使用 LIMIT 条g是一个好的方法。下面是一个示例:(x)<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">while</span><span style="color: #000000; "> (</span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">) {<br /> </span><span style="color: #339966;">   </span><span style="color: #339966;">//</span><span style="color: #339966;">每次只做1000?/span><span style="color: #000000; "><br />    mysql_query("</span><span style="color: #0000FF; ">DELETE</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">FROM</span><span style="color: #000000; "> logs </span><span style="color: #0000FF; ">WHERE</span><span style="color: #000000; "> log_date </span><span style="color: #808080; "><=</span><span style="color: #000000; "> </span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">2009-11-01</span><span style="color: #FF0000; ">'</span><span style="color: #000000; "> LIMIT </span><span style="color: #800000; font-weight: bold; ">1000</span><span style="color: #000000; ">");<br />    </span><span style="color: #0000FF; ">if</span><span style="color: #000000; "> (mysql_affected_rows() </span><span style="color: #808080; ">==</span><span style="color: #000000; "> </span><span style="color: #800000; font-weight: bold; ">0</span><span style="color: #000000; ">) {<br /></span><span style="color: #339966;">        </span><span style="color: #339966;">//</span><span style="color: #339966;"> 没得可删?jin),退出!</span><span style="color: #000000; "><br />        </span><span style="color: #0000FF; ">break</span><span style="color: #000000; ">;<br />    }<br /></span><span style="color: #339966;">    </span><span style="color: #339966;">//</span><span style="color: #339966;"> 每次都要休息一?x)?/span><span style="color: #000000; "><br />    usleep(</span><span style="color: #800000; font-weight: bold; ">50000</span><span style="color: #000000; ">);<br />}</span></div></p><h4>18. 小的列?x)越?/h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">对于大多数的数据库引擎来_(d)盘操作可能是最重大的瓶颈。所以,把你的数据变得紧凑会(x)对这U情况非常有帮助Q因减少?jin)对盘的访问?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">参看 MySQL 的文?nbsp;<a target="_blank" style="color: #2970a6; text-decoration: none;">Storage Requirements</a> 查看所有的数据cd?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">如果一个表只会(x)有几列Ş?jin)(比如说字典表Q配|表Q,那么Q我们就没有理由使用 INT 来做主键Q?MEDIUMINT, SMALLINT 或是更小?TINYINT ?x)更l济一些。如果你不需要记录时_(d)使用 DATE 要比 DATETIME 好得多?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">当然Q你也需要留够够的扩展I间Q不?dng)你日后来q这个事Q你?x)死的很隄Q参?a target="_blank" style="color: #2970a6; text-decoration: none;">Slashdot的例?/a>Q?009q?1?6日)(j)Q一个简单的ALTER TABLE语句׃(jin)3个多时Q因为里面有一千六百万条数据?/p><h4>19. 选择正确的存储引?/h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">?MySQL 中有两个存储引擎 MyISAM ?InnoDBQ每个引擎都有利有弊。酷壳以前文章?a target="_blank" style="color: #2970a6; text-decoration: none;">MySQL: InnoDB q是 MyISAM?</a>》讨论和q个事情?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">MyISAM 适合于一些需要大量查询的应用Q但其对于有大量写操作ƈ不是很好。甚至你只是需要update一个字D,整个表都?x)被锁v来,而别的进E,q是读q程都无法操作直到读操作完成。另外,MyISAM 对于 SELECT COUNT(*) q类的计是快无比的?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">InnoDB 的趋势会(x)是一个非常复杂的存储引擎Q对于一些小的应用,它会(x)?MyISAM q慢。他是它支持“行锁” Q于是在写操作比较多的时候,?x)更优秀。ƈ且,他还支持更多的高U应用,比如Q事务?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">下面是MySQL的手?/p><ul style="margin: 0px; padding: 0px 0px 10px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><li style="margin: 0px; padding: 0px 0px 0px 20px; list-style-position: inside;"><a style="color: #2970a6; text-decoration: none;">target=”_blank”MyISAM Storage Engine</a></li><li style="margin: 0px; padding: 0px 0px 0px 20px; list-style-position: inside;"><a target="_blank" style="color: #2970a6; text-decoration: none;">InnoDB Storage Engine</a></li></ul><h4>20. 使用一个对象关pL器QObject Relational MapperQ?/h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">使用 ORM (Object Relational Mapper)Q你能够获得可靠的性能增涨。一个ORM可以做的所有事情,也能被手动的~写出来。但是,q需要一个高U专家?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">ORM 的最重要的是“Lazy Loading”Q也是_(d)只有在需要的d值的时候才?x)去真正的去做。但你也需要小?j)这U机制的副作用,因ؓ(f)q很有可能会(x)因ؓ(f)要去创徏很多很多的查询反而会(x)降低性能?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">ORM q可以把你的SQL语句打包成一个事务,q会(x)比单独执行他们快得多得多?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">目前Q个人最喜欢的PHP的ORM是:(x)<a target="_blank" style="color: #2970a6; text-decoration: none;">Doctrine</a>?/p><h4>21. 心(j)“怹链接”</h4><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">“怹链接”的目的是用来减少重新创徏MySQL链接的次数。当一个链接被创徏?jin),它?x)永远处在q接的状态,q是数据库操作已经l束?jin)。而且Q自从我们的Apache开始重用它的子q程?#8212;—也就是说Q下一ơ的HTTPh?x)重用Apache的子q程Qƈ重用相同?MySQL 链接?/p><ul style="margin: 0px; padding: 0px 0px 10px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;"><li style="margin: 0px; padding: 0px 0px 0px 20px; list-style-position: inside;"><a target="_blank" style="color: #2970a6; text-decoration: none;">PHP手册Qmysql_pconnect()</a></li></ul><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">在理Z来说Q这听v来非常的不错。但是从个hl验Q也是大多数人的Q上来说Q这个功能制造出来的ȝ(ch)事更多。因为,你只有有限的链接敎ͼ内存问题Q文件句柄数Q等{?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">而且QApache q行在极端ƈ行的环境中,?x)创建很多很多的了(jin)进E。这是Z么这U?#8220;怹链接”的机制工作地不好的原因。在你决定要使用“怹链接”之前Q你需要好好地考虑一下你的整个系l的架构?/p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">文章Q?a target="_blank" style="color: #2970a6; text-decoration: none;">来源</a></p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Arial, Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; line-height: 22px;">Q全文完Q?br /><br />本文转自Q?a style="font-family: verdana, 'courier new'; line-height: 21px;">http://coolshell.cn/articles/1846.html</a></p><img src ="http://www.shnenglu.com/wanghaiguang/aggbug/204490.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/wanghaiguang/" target="_blank">王v?/a> 2013-11-28 11:40 <a href="http://www.shnenglu.com/wanghaiguang/archive/2013/11/28/204490.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++ ADO q接 mysqlhttp://www.shnenglu.com/wanghaiguang/archive/2013/03/07/198266.html王v?/dc:creator>王v?/author>Thu, 07 Mar 2013 07:30:00 GMThttp://www.shnenglu.com/wanghaiguang/archive/2013/03/07/198266.htmlhttp://www.shnenglu.com/wanghaiguang/comments/198266.htmlhttp://www.shnenglu.com/wanghaiguang/archive/2013/03/07/198266.html#Feedback0http://www.shnenglu.com/wanghaiguang/comments/commentRss/198266.htmlhttp://www.shnenglu.com/wanghaiguang/services/trackbacks/198266.html1、安?/span>mysql-5.0.22-win32Q?/span>mysql-connector-odbc-5.1.12-win32.msi
    然后Q开始菜单->讄Q?gt;控制面板Q?gt;理工具Q?gt;数据?ODBC)Q?gt;pȝDSNQ?gt;dQ?gt;选择MySQL ODBC 5.1 Driver

2、首先导入ADOcd库,(zhn)的环境中msado15.dll不一定在q个目录下,h实际情况修改。或者把msado15.dllq个文g拯C的工E目录下Q直?import "msado15.dll" \ no_namespace \rename ("EOF", "adoEOF")包含q来?/span>
在stdafx.h加入如下代码Q?/span>
#include <afxdb.h>        // MFC Automation classes
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")

3、代码示例:(x)

.h文gQ?br />
/************************************************************************
*Copyright:
*FileName:ADOConn.h
*
*Author:wanghaiguang
*Date:2013-03-07
*Description:ADO Operate MySql DataBase
***********************************************************************
*/

#pragma once

class CADOConn
{
public:
    CADOConn(void);
    ~CADOConn(void);

public:
    //d一个指向Connection对象的指?
    _ConnectionPtr m_pConnection;
    //d一个指向Recordset对象的指?
    _RecordsetPtr m_pRecordset;
    // 定义Ҏ(gu)
public:
    // 初始?#8212;q接数据?/span>
    void OnInitADOConn();
    // 执行查询
    _RecordsetPtr& GetRecordSet(_bstr_t bstrSQL);
    // 执行SQL语句QInsert Update _variant_t
    BOOL ExecuteSQL(_bstr_t bstrSQL);
    void ExitConnect();
};

.cpp文gQ?br />
#include "StdAfx.h"
#include "ADOConn.h"

CADOConn::CADOConn(void)
{
}

CADOConn::~CADOConn(void)
{
}

/************************************************************************
*Function   : OnInitADOConn
*Description: Init DataBase Connect
*param      : bconString[in] ()
*return     : void
***********************************************************************
*/
void  CADOConn::OnInitADOConn()
{
    // 初始化OLE/COM库环?nbsp;
    ::CoInitialize(NULL);
    HRESULT hr;
      
    try
    {
         // 创徏Connection对象,可以通过配置文g获取q接信息
         hr = m_pConnection.CreateInstance("ADODB.Connection");
         if(SUCCEEDED(hr))
         {
             m_pConnection->ConnectionTimeout=600;//讄q接时旉
             m_pConnection->CommandTimeout=120;//讄执行命o(h)时旉
        
             m_pConnection->Open("DSN=MySqlTest;Server= localhost;Database=school","root","sa",adModeUnknown);
         }
    } 
    // 捕捉异常
    catch(_com_error e)
    {
        // 昄错误信息
        AfxMessageBox(e.Description());
    }
}

/************************************************************************
*Function   : GetRecordSet
*Description: Select Data
*param      : bstrSQL[in] SQL
*return     : _RecordsetPtr
***********************************************************************
*/
_RecordsetPtr&  CADOConn::GetRecordSet(_bstr_t bstrSQL)
{
    try
    {
        // q接数据库,如果Connection对象为空Q则重新q接数据?/span>
        if(m_pConnection==NULL)
            OnInitADOConn();
        // 创徏记录集对?/span>
        m_pRecordset.CreateInstance(__uuidof(Recordset));
        // 取得表中的记?/span>
        m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
    }
    // 捕捉异常
    catch(_com_error e)
    {
        // 昄错误信息
        AfxMessageBox(e.Description());
    }
    // q回记录?/span>
    return m_pRecordset;
}

/************************************************************************
*Function   : ExecuteSQL
*Description: Exec SQL For Insert Update _variant_t
*param      : bstrSQL[in] SQL
*return     : BOOL
***********************************************************************
*/
BOOL CADOConn::ExecuteSQL(_bstr_t bstrSQL)
{
    // _variant_t RecordsAffected;
    try
    {
        // 是否已经q接数据?/span>
        if(m_pConnection == NULL)
                OnInitADOConn();
        // Connection对象的ExecuteҎ(gu):(_bstr_t CommandText, 
        
// VARIANT * RecordsAffected, long Options ) 
        
// 其中CommandText是命令字Ԍ通常是SQL命o(h)?br />        // 参数RecordsAffected是操作完成后所影响的行? 
        
// 参数Options表示CommandText的类型:(x)adCmdText-文本命o(h)QadCmdTable-表名
        
// adCmdProc-存储q程QadCmdUnknown-未知
        m_pConnection->Execute(bstrSQL,NULL,adCmdText);
        return true;
    }
    catch(_com_error e)
    {
        AfxMessageBox(e.Description());
        return false;
    }
}

/************************************************************************
*Function   : ExitConnect
*Description: Exit Connect DataBase
*param      : 
*return     : void
***********************************************************************
*/
void CADOConn::ExitConnect()
{
    // 关闭记录集和q接
    if (m_pRecordset != NULL)
    {
        m_pRecordset->Close();
        //m_pRecordset->Release();
    }
    m_pConnection->Close();
    //m_pConnection->Release();
    
// 释放环境
    ::CoUninitialize();
}

其他q接数据库:(x)

BOOL ConnectMySqlFun1()
{
    CoInitialize(NULL); //初始化Comlg
    conPtr.CreateInstance(__uuidof(Connection)); //Connection用于与数据库服务器的链接另一U方?/span>
    /******************q接数据?*******************/
    try
    {
        // MySqlTest为数据源?nbsp;localhost表示本地 root表示用户?nbsp;sa表示密码
        conPtr->Open("DSN=MySqlTest;server=localhost;database=school;","root","sa",adModeUnknown);///q接MySql数据?试成功)
    }
    catch(_com_error e) //捕捉异常
    {
        printf("Connect Error : %s", e.Description());
        return FALSE;
    }

    return TRUE;
}

BOOL ConnectMySqlFun2()
{
    CoInitialize(NULL); //初始化Comlg
    try
    {
        //创徏q接对象实例
        conPtr.CreateInstance("ADODB.Connection");
        //讄q接字符?br />        //mdb------------------------------------------------
        CString strConnect="DSN=MySqlTest";
        //使用OpenҎ(gu)q接数据?/span>
        conPtr->Open((_bstr_t)strConnect,"root","sa",adModeUnknown);
    }
    catch(_com_error e)
    {
        printf("Connect Error : %s", e.Description());
        return FALSE;
    }
    return TRUE;
}

操作MySql数据?
    CADOConn m_ADO;
    m_ADO.OnInitADOConn();
        
    //讄SELECT语句
    _bstr_t vSQL, vInserSQL;
    vSQL = "select name from teacher";
    //讄INSERT语句
    vInserSQL = "insert into teacher values(27, 'hai', '哈尔滨六?, '1998-05-05')";
    ///执行INSERT语句
    if (m_ADO.ExecuteSQL(vInserSQL))
    {
        printf("Insert Data Successful!!!");
    }

    //执行SELETE语句
    _RecordsetPtr m_pRecordset;
    m_pRecordset = m_ADO.GetRecordSet(vSQL);

    CString name0;
    //q回各列的?/span>
    while (!m_pRecordset->adoEOF)
    {
        name0 = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name");
        //CString name=(CString)recordPtr->GetCollect(_variant_t("name")).bstrVal;
        
//int no=recordPtr->GetCollect(_variant_t("stuno")).intVal;
        printf("name : %s\n", name0);
        m_pRecordset->MoveNext();
    }
    //断开与数据库的连?/span>
    m_ADO.ExitConnect();

参考链接:(x)http://www.shnenglu.com/current/archive/2009/07/24/91069.html

]]>
dbW记?/title><link>http://www.shnenglu.com/wanghaiguang/archive/2013/02/27/198118.html</link><dc:creator>王v?/dc:creator><author>王v?/author><pubDate>Wed, 27 Feb 2013 08:13:00 GMT</pubDate><guid>http://www.shnenglu.com/wanghaiguang/archive/2013/02/27/198118.html</guid><wfw:comment>http://www.shnenglu.com/wanghaiguang/comments/198118.html</wfw:comment><comments>http://www.shnenglu.com/wanghaiguang/archive/2013/02/27/198118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/wanghaiguang/comments/commentRss/198118.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/wanghaiguang/services/trackbacks/198118.html</trackback:ping><description><![CDATA[<div class="rn9xp1b" id="cnblogs_post_body" style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; word-break: normal !important;"><table border="0" align="left" style="border-style: solid; border-color: #c0c0c0; border-collapse: collapse;"><tbody><tr><td align="left" valign="top" style="font-size: 12px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; padding: 3px; word-break: normal !important;"><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">mysql资源</p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql5.1中文参考手?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">mysql理</p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="homepage1_HomePageDays_DaysList_DayItem_0_DayList_0_TitleUrl_0" style="color: navy; text-decoration: initial;">Zlinux使用mysql二进制包安装mysql5.5</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="homepage1_HomePageDays_DaysList_DayItem_0_DayList_0_TitleUrl_5" style="color: navy; text-decoration: initial;">mysql client命o(h)行选项</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysqld服务器系l变量和状态变?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql SQL服务器模?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql 账户理</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql日志文g</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql列类?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql数据库操?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql创徏和删除表</a><a style="color: navy; text-decoration: initial;"><br /></a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql修改?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql索引操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">mysql索引详解</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">mysql select操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql insert操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">mysql load操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql update操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">mysql 删除操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql join操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql子查?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql函数</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql show操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql flush操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql kill操作</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql表维护操?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql导入导出</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p></td><td align="left" valign="top" style="font-size: 12px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; padding: 3px; word-break: normal !important;"><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">mysql调优</p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">MySQL执行计划解读</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL Profiling 的?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    <a style="color: navy; text-decoration: initial;">mysql常见sql优化</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql日志讄优化</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL~存参数优化</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL表结构优?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL 索引优化</a> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL SQL优化</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">MySQ 存储引擎选择</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">   <a style="color: navy; text-decoration: initial;">MySQLg瓉分析</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">g环境对系l性能的媄(jing)?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL内存?sh)?全局׃n</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL内存?sh)?U程独n</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">mysql数据库锁定机?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="homepage1_HomePageDays_DaysList_DayItem_0_DayList_0_TitleUrl_0" style="color: navy; text-decoration: initial;">Join的实现原理及(qing)优化思\</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql ORDER BY,GROUP BY 和DISTINCT原理</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">mysql架构</p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">mysql主要应用场景</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">MySQL Serverpȝ架构</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">MySQL Replication 常用架构</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">可扩展性设计之数据切分</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="homepage1_HomePageDays_DaysList_DayItem_0_DayList_0_TitleUrl_2" style="color: navy; text-decoration: initial;">可扩展性设计之Cache与Search的利?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p></td><td align="left" valign="top" style="font-size: 12px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; padding: 3px; word-break: normal !important;"><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">nosql</p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">NoSQL数据库笔?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">redis</p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">redis官方文档</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">redis中文官方文档</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a rel="bookmark" style="color: navy; text-decoration: initial;">Redis命o(h)参考中文版译</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  入门资料</p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    <a style="color: navy; text-decoration: initial;">Redis新手入门详解</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    <a style="color: navy; text-decoration: initial;">redis快速入门详解PPT</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    <a style="color: navy; text-decoration: initial;">redis中文入门手册</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    <a style="color: navy; text-decoration: initial;">redis深入出</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">Redis数据?-Redis的Virtual Memory介绍</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">Redis 或弃用当?VM 机制Q采用新?diskstore 模型</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a id="cb_post_title_url" style="color: navy; text-decoration: initial;">Redis内存?sh)用优化与存?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">节约内存QInstagram的Redis实践</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a rel="bookmark" style="color: navy; text-decoration: initial;">Redisq阶教程-aof(append only file)日志文g</a> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"><a rel="bookmark" style="color: navy; text-decoration: initial;"> </a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">Redis作者谈Redis应用场景</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">Memcached真的q时?jin)吗Q看看Redis作者怎么?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a rel="bookmark" style="color: navy; text-decoration: initial;">谈Redis数据库的键D?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a rel="bookmark" style="color: navy; text-decoration: initial;">案例Q用Redis来存储关注关p?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a rel="bookmark" style="color: navy; text-decoration: initial;">Bump的Redis应用l验</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">Redis定w?qing)用规?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">Redis几个认识误区</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">使用Redis的五个注意事?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    <a style="color: navy; text-decoration: initial;">Redis大数据之?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">新浪微博开攑^C的redis实践</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">Redisq维之道</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a target="_blank" style="color: navy; text-decoration: initial;">Redis复制与可扩展集群搭徏</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">    <a style="color: navy; text-decoration: initial;">Redis监控技?/a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  <a style="color: navy; text-decoration: initial;">深入Redis内部-Redis 源码讲解</a></p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="font-size: 13px; line-height: 1.4; margin-top: 10px; margin-bottom: 10px;">  </p></td></tr></tbody></table><p style="line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p><p style="line-height: 1.4; margin-top: 10px; margin-bottom: 10px;"> </p></div><div class="djn39rv" id="MySignature" style="margin-top: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"></div><div style="clear: both; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"></div><font face="Verdana, Geneva, Arial, Helvetica, sans-serif" size="2"><span style="line-height: 19px;"><br />本文转自Q?/span></font>http://www.cnblogs.com/ggjucheng/archive/2012/11/02/2751119.html <img src ="http://www.shnenglu.com/wanghaiguang/aggbug/198118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/wanghaiguang/" target="_blank">王v?/a> 2013-02-27 16:13 <a href="http://www.shnenglu.com/wanghaiguang/archive/2013/02/27/198118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Q{载)(j)MySQL索引背后的数据结构及(qing)法原理http://www.shnenglu.com/wanghaiguang/archive/2013/01/07/197077.html王v?/dc:creator>王v?/author>Mon, 07 Jan 2013 08:43:00 GMThttp://www.shnenglu.com/wanghaiguang/archive/2013/01/07/197077.htmlhttp://www.shnenglu.com/wanghaiguang/comments/197077.htmlhttp://www.shnenglu.com/wanghaiguang/archive/2013/01/07/197077.html#Feedback0http://www.shnenglu.com/wanghaiguang/comments/commentRss/197077.htmlhttp://www.shnenglu.com/wanghaiguang/services/trackbacks/197077.html阅读全文

]]>
MongoDB实战开?/title><link>http://www.shnenglu.com/wanghaiguang/archive/2012/04/13/171223.html</link><dc:creator>王v?/dc:creator><author>王v?/author><pubDate>Fri, 13 Apr 2012 04:35:00 GMT</pubDate><guid>http://www.shnenglu.com/wanghaiguang/archive/2012/04/13/171223.html</guid><wfw:comment>http://www.shnenglu.com/wanghaiguang/comments/171223.html</wfw:comment><comments>http://www.shnenglu.com/wanghaiguang/archive/2012/04/13/171223.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/wanghaiguang/comments/commentRss/171223.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/wanghaiguang/services/trackbacks/171223.html</trackback:ping><description><![CDATA[<div><span style="font-size: 18pt">相关文章链接Q?br /><br /></span><u><font color="#800080"><span style="font-size: 18pt"><a >http://special.csdn.net/mongodb/</a><br /></span></font></u><a ><span style="font-size: 18pt">http://www.cnblogs.com/fish-li/archive/2011/06/26/2090800.html#_labelStart</span></a><br /><br /><br /><span style="font-size: 18pt">Hadoop<br /></span><br /> <p>一?a target="_blank">分布式系l?/a>基础架构Q由Apache基金?x)开发。用户可以在不了(jin)解分布式底层l节的情况下Q开发分布式E序。充分利用集的威力高速运和存储。Hadoop实现?jin)一?a target="_blank">分布式文件系l?/a>QHadoop Distributed File SystemQ,UHDFS。HDFS有着高容错性的特点Qƈ且设计用来部|在低廉的(low-costQ硬件上。而且它提供高?sh)输率(high throughputQ来讉K<a target="_blank">应用E序</a>的数据,适合那些有着大数据集(large data setQ的应用E序。HDFS攑֮?jin)(relaxQPOSIX的要求(requirementsQ这样可以流的Ş式访问(streaming accessQ文件系l中的数据?/p><br /><span style="font-size: 18pt">joomla <br /></span><br />QContent Management System, CMSQ,它属于PortalQ企业入口网站)(j)cdQ顾名思义Q就是比较适合作ؓ(f)商业cd的网站程序。一般h对这cd?a target="_blank">内容理pȝ</a>可能?x)有以下的别名来U呼Q? <div id="9jpd9hn" class="spctrl"></div>  ■ 架站E序Q或<a target="_blank">软g</a>Q? <div id="t3bvdtt" class="spctrl"></div>  ■ 快速架站程序(或YӞ(j) <div id="9zjhdbr" class="spctrl"></div>  ■ 整站E序 </div><img src ="http://www.shnenglu.com/wanghaiguang/aggbug/171223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/wanghaiguang/" target="_blank">王v?/a> 2012-04-13 12:35 <a href="http://www.shnenglu.com/wanghaiguang/archive/2012/04/13/171223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.ekqz.cn" target="_blank">޾ƷþþþĻ69 </a>| <a href="http://www.thebeaver.cn" target="_blank">91þþþþþ</a>| <a href="http://www.jzxqbz.cn" target="_blank">ɫͷվþ</a>| <a href="http://www.231it.cn" target="_blank">þù</a>| <a href="http://www.jdongshop.cn" target="_blank">ɫ99þþþø߳ۺӰԺ</a>| <a href="http://www.b947.cn" target="_blank">þþоƷĻ</a>| <a href="http://www.qvella.cn" target="_blank">þĻ</a>| <a href="http://www.jfhtgj.cn" target="_blank">ŷ޹Ʒþ</a>| <a href="http://www.liangfang013.cn" target="_blank">޹Ʒ18þþþþ</a>| <a href="http://www.cqmh.com.cn" target="_blank">þòӰ</a>| <a href="http://www.xecwf.cn" target="_blank">ȫɫƴɫƬѾþþ</a>| <a href="http://www.hjpz333.cn" target="_blank">Ʒþþһ</a>| <a href="http://www.oceanchemlab.cn" target="_blank">þۺ97ɫһһ </a>| <a href="http://www.gcxd.net.cn" target="_blank">˾þþƷһ</a>| <a href="http://www.ssc629.cn" target="_blank">þ99Ʒþþþþ</a>| <a href="http://www.yrjiameng.cn" target="_blank">ŷþۺ</a>| <a href="http://www.269sihu.cn" target="_blank">þרƷ</a>| <a href="http://www.xajh2.cn" target="_blank">þþƷ</a>| <a href="http://www.kpqo.cn" target="_blank">99þ99þþþƷ</a>| <a href="http://www.ylfyw.cn" target="_blank">ŷ޾þav</a>| <a href="http://www.qunlanggu.cn" target="_blank">91Ʒ91þþþþ</a>| <a href="http://www.yb121.com.cn" target="_blank">þˬˬAVƬ</a>| <a href="http://www.seo30.cn" target="_blank">ٸ߳ҽоþþ</a>| <a href="http://www.qnzj.org.cn" target="_blank">޹˾Ʒþþùһ </a>| <a href="http://www.lordswar.cn" target="_blank">þѾƷav</a>| <a href="http://www.114best.com.cn" target="_blank">ҹƷƬþ</a>| <a href="http://www.sh-ar.cn" target="_blank">þþƷһ</a>| <a href="http://www.byhyri.cn" target="_blank">þþƷav鶹ͼƬ</a>| <a href="http://www.tja4.cn" target="_blank">wwwþ</a>| <a href="http://www.by1506.cn" target="_blank">ž99Ʒþþþþ</a>| <a href="http://www.vtkh.cn" target="_blank">þþþ99ƷƬŷ </a>| <a href="http://www.vstmall.com.cn" target="_blank">ҹ޾þþþþþþ</a>| <a href="http://www.rmbo.cn" target="_blank">޾ƷƵþþ</a>| <a href="http://www.aamih.cn" target="_blank">߳߳þþ91 </a>| <a href="http://www.lockdealing.cn" target="_blank">ŷպĻþþò</a>| <a href="http://www.songshuidaojia.cn" target="_blank">ƷþþþAV</a>| <a href="http://www.v2beta.cn" target="_blank">þѿaëƬ</a>| <a href="http://www.hfpump.com.cn" target="_blank">޾Ʒ97þĻ</a>| <a href="http://www.moonlong.cn" target="_blank">˾þ</a>| <a href="http://www.iamwilson.cn" target="_blank">޾Ʒ97þĻ</a>| <a href="http://www.pyspiderking.cn" target="_blank">þþþþþ޾Ʒ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>