<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[MyISAM Key Cache]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 22 Apr 2010 07:51:54 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	1. 如何配置Key Cache的大小<br/><br/><br/>#配置文件my.cnf<br/>key_buffer_size=50*1024*1024<br/><br/>另外，Key Cache的大小可以动态的改变<br/><br/>2. 给数据表划分单独的Key Cache<br/><br/>例如：划分一块128K的Key buffer空间，指定数据表t1的Key cache放在里面。最后演示了如何删除这个特定的Key buffer空间。<br/><br/><br/>SET GLOBAL hot_cache.key_buffer_size=128*1024;<br/>CACHE INDEX t1 IN hot_cache;<br/>SET GLOBAL&nbsp;&nbsp;hot_cache.key_buffer_size=0;<br/><br/>3. 预先载入某些数据表的索引<br/><br/><br/>LOAD INDEX INTO CACHE t1, t2<br/><br/>4. 关于Key Cache的使用情况观察 Flush现象<br/><br/><br/>mysql&gt; show status like &quot;key%&quot;;<br/>+------------------------+----------+<br/>&#124; Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; Value&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>+------------------------+----------+<br/>&#124; Key_blocks_not_flushed &#124; 14468&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>&#124; Key_blocks_unused&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>&#124; Key_blocks_used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 14497&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>&#124; Key_read_requests&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 30586575 &#124;<br/>&#124; Key_reads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 157&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>&#124; Key_write_requests&nbsp;&nbsp;&nbsp;&nbsp; &#124; 7100408&nbsp;&nbsp;&#124;<br/>&#124; Key_writes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#124; 1199800&nbsp;&nbsp;&#124;<br/>+------------------------+----------+<br/>mysql&gt; flush tables;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （注意，请不要在业务高峰期执行）<br/>+------------------------+----------+<br/>&#124; Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; Value&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>+------------------------+----------+<br/>&#124; Key_blocks_not_flushed &#124; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;&nbsp;&nbsp; #所有修改的block都已经被flush了<br/>&#124; Key_blocks_unused&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>&#124; Key_blocks_used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 14497&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>&#124; Key_read_requests&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 38333936 &#124;<br/>&#124; Key_reads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; 207&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>&#124; Key_write_requests&nbsp;&nbsp;&nbsp;&nbsp; &#124; 8819898&nbsp;&nbsp;&#124;<br/>&#124; Key_writes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#124; 1255245&nbsp;&nbsp;&#124;<br/>+------------------------+----------+<br/><br/>5. 需要注意的事项<br/><br/>内存中缓存的索引块（Key Cache），有时候并不会及时刷新到磁盘上，所以对于正在运行的数据表的索引文件（MYI）一般都是不完整的。如果此时拷贝或者移动这些索引文件。多半会出现索引文件损坏的情况。<br/><br/>可以通过Flush table命令来将Key Cache中的block都flush到磁盘上。所以，一般要动态移动MyISAM表需要执行以下步骤：<br/><br/>首先，刷新数据表，并锁住数据表：（注意，请不要在业务高峰期执行）<br/><br/><br/>FLUSH TABLES WITH READ LOCK;<br/><br/>可以通过下面的命令来查看没有被Flush的索引块数量<br/><br/><br/>mysql&gt; show status like &quot;Key_blocks_not_flushed&quot;;<br/>+------------------------+----------+<br/>&#124; Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124; Value&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>+------------------------+----------+<br/>&#124; Key_blocks_not_flushed &#124; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#124;<br/>+------------------------+----------+<br/><br/>最后，移动对应的文件（MYI MYD FRM）。<br/><br/>让我突然想起：张宴 Nginx 0.8.x + PHP 5.2.13（FastCGI）搭建胜过Apache十倍的Web服务器（第6版）[原创] 第6版本<br/><br/>http://blog.s135.com/nginx_php_v6/<br/>创建my.cnf配置文件：<br/>vi /data0/mysql/3306/my.cnf<br/><br/>里面就有：<br/><br/><br/><div class="code">relay-log-index = /data0/mysql/3306/relaylog/relaylog<br/>relay-log-info-file = /data0/mysql/3306/relaylog/relaylog<br/>relay-log = /data0/mysql/3306/relaylog/relaylog<br/>expire_logs_days = 30<br/>key_buffer_size = 256M</div><br/><br/>256M就是用来配置缓存的，呵呵，果然。
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] MyISAM Key Cache]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>