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

<channel>
	<title>五四陈科学院-坚信科学，分享技术 &#187; mysql</title>
	<atom:link href="http://www.54chen.com/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.54chen.com</link>
	<description>PHP、JAVA、缓存、架构、经验、分享</description>
	<lastBuildDate>Fri, 10 Feb 2012 12:21:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>硬件为王，软件为帝--记突增的访问</title>
		<link>http://www.54chen.com/_linux_/king-of-the-server.html</link>
		<comments>http://www.54chen.com/_linux_/king-of-the-server.html#comments</comments>
		<pubDate>Sat, 14 May 2011 16:22:07 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[架构研究]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[中间层]]></category>
		<category><![CDATA[创业]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/king-of-the-server.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>五一归来两周，精力都放在了因为服务器压力突增而来的各种鸡飞狗跳的事情上，今天总结一下，算是对过去两周的总结，希望对各创业团队有所借鉴。 1.访问突增，连锁反应 最先开始出现问题的，是在小负载下没有出现的问题，在大压力时，只要DB一堵，表像就会是循环锁死。 解决之道： 服务要有清晰的架构，开发规范里一定要有明确的架构层次规范，最好还有代码的层次规范。 2.mysql设计不合理，压力指数增加 mysql中存在大量的更新操作，特别是大字段或者变长字段的频繁更新，导致磁盘io居高不下，慢查询越来越多。 硬解决之道： raid卡加电，开启raid写缓存：一般服务器的raid卡都没有开启，开启是有一定用处的，但有一个前提，不是待续的高写入，否则这个写缓存是没有意义的。电池充电时无法缓存，一般三个月充一次电。 转微博：FusionioChina 回复 @YauzZ:多一个故障点。多一份丢数据的可能。而且目前有Raid卡的内存做到1GB。丢不起呀。(5月11日 23:29) 从raid分到多个盘、盘柜，都是从硬件上用多硬盘分担的好方案。 软解决之道： 写方案建立mysql隔离层，在写入前预先处理，类似软件缓存方案，效果明显，修改复杂。 3.后续可做 灵活的中间层数据层切换逻辑，让负载可以随时转移、分隔，基本可以达到“人傻钱多，万事不愁”。<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img03.taobaocdn.com/imgextra/i3/T1pM1bXgdlXXapI9ra_122249.jpg" alt="mysql" width=250 /><br />
五一归来两周，精力都放在了因为服务器压力突增而来的各种鸡飞狗跳的事情上，今天总结一下，算是对过去两周的总结，希望对各创业团队有所借鉴。<br />
1.访问突增，连锁反应<br />
最先开始出现问题的，是在小负载下没有出现的问题，在大压力时，只要DB一堵，表像就会是循环锁死。<br />
解决之道：<br />
服务要有清晰的架构，开发规范里一定要有明确的架构层次规范，最好还有代码的层次规范。</p>
<p>2.mysql设计不合理，压力指数增加<br />
mysql中存在大量的更新操作，特别是大字段或者变长字段的频繁更新，导致磁盘io居高不下，慢查询越来越多。<br />
硬解决之道：<br />
       raid卡加电，开启raid写缓存：一般服务器的raid卡都没有开启，开启是有一定用处的，但有一个前提，不是待续的高写入，否则这个写缓存是没有意义的。电池充电时无法缓存，一般三个月充一次电。<br />
       转微博：FusionioChina 回复 @YauzZ:多一个故障点。多一份丢数据的可能。而且目前有Raid卡的内存做到1GB。丢不起呀。(5月11日 23:29)<br />
       从raid分到多个盘、盘柜，都是从硬件上用多硬盘分担的好方案。</p>
<p>软解决之道：<br />
       写方案建立mysql隔离层，在写入前预先处理，类似软件缓存方案，效果明显，修改复杂。</p>
<p>3.后续可做<br />
       灵活的中间层数据层切换逻辑，让负载可以随时转移、分隔，基本可以达到“人傻钱多，万事不愁”。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/king-of-the-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>利用sqoop将mysql数据同步到hive手记</title>
		<link>http://www.54chen.com/java-ee/sqoop-mysql-to-hive.html</link>
		<comments>http://www.54chen.com/java-ee/sqoop-mysql-to-hive.html#comments</comments>
		<pubDate>Thu, 21 Apr 2011 07:28:01 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[hive]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sqoop]]></category>

		<guid isPermaLink="false">http://www.54chen.com/java-ee/sqoop-mysql-to-hive.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>1.下载 http://archive.cloudera.com/cdh/3/sqoop-1.2.0-CDH3B4.tar.gz 2.下载 http://archive.cloudera.com/cdh/3/hadoop-0.20.2-CDH3B4.tar.gz 3.解压 2 4.复制3里hadoop-core-0.20.2-CDH3B4.jar到sqoop的lib下 5.在某处复制mysql-connector-java-5.1.10.jar到sqoop的lib下 6.修改configure-sqoop 注释掉hbase zookeeper检查： #if [ ! -d "${HBASE_HOME}" ]; then # echo "Error: $HBASE_HOME does not exist!" # echo 'Please set $HBASE_HOME to the root of your HBase installation.' # exit 1 &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img01.taobaocdn.com/imgextra/i1/T14rp.XdVmXXa7cv.Z_032332.jpg" alt="sqoop mysql hive" /></p>
<p>1.下载 http://archive.cloudera.com/cdh/3/sqoop-1.2.0-CDH3B4.tar.gz</p>
<p>2.下载 http://archive.cloudera.com/cdh/3/hadoop-0.20.2-CDH3B4.tar.gz</p>
<p>3.解压 2</p>
<p>4.复制3里hadoop-core-0.20.2-CDH3B4.jar到sqoop的lib下</p>
<p>5.在某处复制mysql-connector-java-5.1.10.jar到sqoop的lib下</p>
<p>6.修改configure-sqoop</p>
<blockquote><p>注释掉hbase zookeeper检查：<br />
#if [ ! -d "${HBASE_HOME}" ]; then<br />
#  echo "Error: $HBASE_HOME does not exist!"<br />
#  echo 'Please set $HBASE_HOME to the root of your HBase installation.'<br />
#  exit 1<br />
#fi<br />
#if [ ! -d "${ZOOKEEPER_HOME}" ]; then<br />
#  echo "Error: $ZOOKEEPER_HOME does not exist!"<br />
#  echo 'Please set $ZOOKEEPER_HOME to the root of your ZooKeeper installation.'<br />
#  exit 1<br />
#fi</p></blockquote>
<p>7.运行：<br />
列出mysql所有的表：</p>
<blockquote><p>./sqoop list-tables --connect jdbc:mysql://127.0.0.1/operation --username root --password 123</p></blockquote>
<p>导入mysql表到hive：</p>
<blockquote><p>./sqoop import --connect jdbc:mysql://192.168.100.52/operation --username root --password 3487e498770b9740086144fc03140876 --table active_uuid --hive-import</p></blockquote>
<p>导入需要表里有主建，还要注意不要使用127.0.0.1，因为map出去不一定在哪个节点执行。</p>
<p>如果曾经执行失败过，那再执行的时候，会有错误提示：</p>
<blockquote><p>ERROR tool.ImportTool: Encountered IOException running import job: org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory xxx already exists</p></blockquote>
<p>执行 $HADOOP_HOME/bin/hadoop fs -rmr xxx 即可     </p>
<p>8.验证:</p>
<blockquote><p>bin/hive<br />
 show tables;多了一个表</p></blockquote>
<p>9.经验：<br />
 sqoop做了一些mysqldump时的map reduce，所以速度会比单纯的dump后load快。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/java-ee/sqoop-mysql-to-hive.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>一条SQL引发的对order by的思考</title>
		<link>http://www.54chen.com/architecture/triggered-by-a-sql-order-by-the-thoughts-on.html</link>
		<comments>http://www.54chen.com/architecture/triggered-by-a-sql-order-by-the-thoughts-on.html#comments</comments>
		<pubDate>Tue, 06 Jul 2010 10:27:27 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[架构研究]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[order by]]></category>

		<guid isPermaLink="false">http://www.54chen.com/architecture/triggered-by-a-sql-order-by-the-thoughts-on.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>==========尽职的安静的分隔线=========== 在实际工作中遇到下面一个问题： 有一个表，存有2000万数据。 主键为ID bigint(20) NOT NULL auto_increment 另有一字段time timestamp NOT NULL default CURRENT_TIMESTAMP 故事从这两个字段说起： sql1需要从这个表中检索出来时间为2010-05-26 11:55:00之前并且id号大于20000的前10条数据 sql2需要从这个表中检索出来时间为2010-05-26 11:55:00之后并且id号大于20000的前10条数据 两条sql写出来大概是这样子的： sql1:select * from table where time 20000 order by id limit 10; sql2:select * from table where time >'2010-05-26 11:55:00' &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img02.taobaocdn.com/imgextra/i2/T18I0FXoFCXXcVYX39_072328.jpg" alt="热" /><br />
==========尽职的安静的分隔线===========<br />
在实际工作中遇到下面一个问题：<br />
有一个表，存有2000万数据。<br />
主键为ID bigint(20) NOT NULL auto_increment<br />
另有一字段time timestamp NOT NULL default CURRENT_TIMESTAMP</p>
<p>故事从这两个字段说起：<br />
sql1需要从这个表中检索出来时间为2010-05-26 11:55:00之<font color=red>前</font>并且id号大于20000的前10条数据<br />
sql2需要从这个表中检索出来时间为2010-05-26 11:55:00之<font color=red>后</font>并且id号大于20000的前10条数据</p>
<p>两条sql写出来大概是这样子的：<br />
sql1:select * from table where time <'2010-05-26 11:55:00' and id>20000 order by id limit 10;<br />
sql2:select * from table where time >'2010-05-26 11:55:00' and id>20000 order by id limit 10;</p>
<p>并且已经知道表中的数据，在上面所示时间之前的数据要远远多于所示时间之后的数据。如图1所示：<br />
<img src="http://img05.taobaocdn.com/imgextra/i5/T1AKhFXgdbXXaH.kQ3_051000.jpg" alt="54chen" /><br />
图1 数据在时间线上的示意图</p>
<p>实测发现，sql1执行时间0.03s，sql2执行时间33s。</p>
<p>为何大于小于运行的速度相比如何巨大？下面来解答。</p>
<p><strong>第一，用explain来观察两条sql的区别</strong><br />
结论：没什么区别</p>
<p><strong>第二，研究order by</strong><br />
将sql2的order by id修改为order by id desc(排序方向颠倒)后，发现速度马上提到了0.03s的水平。<br />
同样修改sql1的时候，速度马上降到了30s的水平。</p>
<p>进行多次测试，排除mysql本身的缓存干扰。</p>
<p>结论：<br />
sql1的运行示意图如图2所示：<br />
<img src="http://img06.taobaocdn.com/imgextra/i6/T1ouhFXgXdXXbLbqg6_060541.jpg" alt="54chen" /><br />
图2 第一条SQL语句快慢解释图</p>
<p>sql2的运行示意图如图3所示：<br />
<img src="http://img02.taobaocdn.com/imgextra/i2/T14KdFXc0eXXc_k476_061836.jpg" alt="54chen" /><br />
图2 第二条SQL语句快慢解释图</p>
<p>综合上面两个图，mySQL在where查询的时候，也许按照where的条件，按照主键的顺序，最后满足条件的，最后进到内存中去，再进行后面的order by时，asc如果在内存中比不在内存中的就要快得多。</p>
<p>未研究真正实现的代码，仅凭感觉验证。<br />
一句话概括是：按照使用的索引，最后满足条件的数据将留在内存里供进一步排序。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/architecture/triggered-by-a-sql-order-by-the-thoughts-on.html/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>mysql explain详解</title>
		<link>http://www.54chen.com/architecture/mysql-explain.html</link>
		<comments>http://www.54chen.com/architecture/mysql-explain.html#comments</comments>
		<pubDate>Wed, 19 May 2010 09:52:55 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[架构研究]]></category>
		<category><![CDATA[explain]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.54chen.com/architecture/mysql-explain.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>doubanclaimed89ad216b01beaf 题注：感谢suchasplus兄弟在第一时间提示explain拼写错误~~~:) 对于经常使用mysql的兄弟们，对explain一定不会陌生。当你在一条SELECT语句前放上关键词EXPLAIN，MySQL解释它将如何处理SELECT，提供有关表如何联合和以什么次序的信息。 借助于EXPLAIN，你可以知道 1)你什么时候必须为表加入索引以得到一个使用索引找到记录的更快的SELECT。 2)你也能知道优化器是否以一个最佳次序联结表。为了强制优化器对一个SELECT语句使用一个特定联结次序，增加一个STRAIGHT_JOIN子句。 官方的关于explain的文档在http://dev.mysql.com/doc/refman/5.1/en/using-explain.html（英文），本文可作为官方文献的不完整通俗读物。 使用的方法 EXPLAIN tbl_name 或： EXPLAIN [EXTENDED] SELECT select_options 前者可以得出一个表的字段结构等等，后者主要是给出相关的一些索引信息，而今天要讲述的重点是后者。 举例 mysql&#62; explain select * from event; +----+-------------+-------+------+---------------+------+---------+------+------+-------+ &#124; id &#124; select_type &#124; table &#124; type &#124; possible_keys &#124; key &#124; key_len &#124; ref &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p style="text-align: center;"><img class="aligncenter" src="http://img07.taobaocdn.com/bao/uploaded/i7/T1cRdAXeVlXXbDaB72_044910.jpg" alt="mysql explain" /></p>
<p><span style="color: #ffffff;">doubanclaimed89ad216b01beaf</span><br />
题注：感谢suchasplus兄弟在第一时间提示explain拼写错误~~~:)</p>
<p>对于经常使用mysql的兄弟们，对explain一定不会陌生。当你在一条SELECT语句前放上关键词EXPLAIN，MySQL解释它将如何处理SELECT，提供有关表如何联合和以什么次序的信息。<br />
借助于EXPLAIN，你可以知道<br />
1)你什么时候必须为表加入索引以得到一个使用索引找到记录的更快的SELECT。<br />
2)你也能知道优化器是否以一个最佳次序联结表。为了强制优化器对一个SELECT语句使用一个特定联结次序，增加一个STRAIGHT_JOIN子句。<br />
官方的关于explain的文档在http://dev.mysql.com/doc/refman/5.1/en/using-explain.html（英文），本文可作为官方文献的不完整通俗读物。</p>
<h2><strong>使用的方法</strong></h2>
<p>EXPLAIN tbl_name<br />
或：<br />
EXPLAIN [EXTENDED] SELECT select_options</p>
<p>前者可以得出一个表的字段结构等等，后者主要是给出相关的一些索引信息，而今天要讲述的重点是后者。</p>
<h2>举例</h2>
<p>mysql&gt; explain select * from event;<br />
+----+-------------+-------+------+---------------+------+---------+------+------+-------+<br />
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra |<br />
+----+-------------+-------+------+---------------+------+---------+------+------+-------+<br />
|  1 | SIMPLE      | event | ALL  | NULL          | NULL | NULL    | NULL |   13 |       |<br />
+----+-------------+-------+------+---------------+------+---------+------+------+-------+<br />
1 row in set (0.00 sec)</p>
<h2><strong>各个属性的含义</strong></h2>
<p>id<br />
select查询的序列号</p>
<p>select_type<br />
select查询的类型，主要是区别普通查询和联合查询、子查询之类的复杂查询。</p>
<p>table<br />
输出的行所引用的表。</p>
<p>type<br />
联合查询所使用的类型。<br />
type显示的是访问类型，是较为重要的一个指标，结果值从好到坏依次是：<br />
system &gt; const &gt; eq_ref &gt; ref &gt; fulltext &gt; ref_or_null &gt; index_merge &gt; unique_subquery &gt; index_subquery &gt; range &gt; index &gt; ALL<br />
一般来说，得保证查询至少达到range级别，最好能达到ref。</p>
<p>possible_keys<br />
指出MySQL能使用哪个索引在该表中找到行。如果是空的，没有相关的索引。这时要提高性能，可通过检验WHERE子句，看是否引用某些字段，或者检查字段不是适合索引。</p>
<p>key<br />
显示MySQL实际决定使用的键。如果没有索引被选择，键是NULL。</p>
<p>key_len<br />
显示MySQL决定使用的键长度。如果键是NULL，长度就是NULL。文档提示特别注意这个值可以得出一个多重主键里mysql实际使用了哪一部分。</p>
<p>ref<br />
显示哪个字段或常数与key一起被使用。</p>
<p>rows<br />
这个数表示mysql要遍历多少数据才能找到，在innodb上是不准确的。</p>
<p>Extra<br />
如果是Only index，这意味着信息只用索引树中的信息检索出的，这比扫描整个表要快。<br />
如果是where used，就是使用上了where限制。<br />
如果是impossible where 表示用不着where，一般就是没查出来啥。<br />
如果此信息显示Using filesort或者Using temporary的话会很吃力，WHERE和ORDER BY的索引经常无法兼顾，如果按照WHERE来确定索引，那么在ORDER BY时，就必然会引起Using filesort，这就要看是先过滤再排序划算，还是先排序再过滤划算。</p>
<h2><strong>常见的一些名词解释</strong></h2>
<p>Using filesort<br />
MySQL需要额外的一次传递，以找出如何按排序顺序检索行。</p>
<p>Using index<br />
从只使用索引树中的信息而不需要进一步搜索读取实际的行来检索表中的列信息。</p>
<p>Using temporary<br />
为了解决查询，MySQL需要创建一个临时表来容纳结果。</p>
<p>ref<br />
对于每个来自于前面的表的行组合，所有有匹配索引值的行将从这张表中读取</p>
<p>ALL<br />
完全没有索引的情况，性能非常地差劲。</p>
<p>index<br />
与ALL相同，除了只有索引树被扫描。这通常比ALL快，因为索引文件通常比数据文件小。</p>
<p>SIMPLE<br />
简单SELECT(不使用UNION或子查询)</p>
<h2><strong>关于哥学社</strong></h2>
<p><a style="color: #0b3b8c; text-decoration: none;" title="哥学社" href="http://www.54chen.com/blog-brother" target="_self">哥学社</a>是一个自由博客组织，以提高原创技术博客质量，为成员博客增加更有效评论，由来自腾讯、百度、盛大、人人网、新浪、奇虎、TOM等各大企业的哥们共同起草发起。</p>
<h2><strong>关于五四陈</strong></h2>
<p>54chen(陈臻)，人人网分布式存储研究人员，业余时间混迹于各技术组织且乐此不疲。目前关注实施PHP培训。对flex等前端技术有一点研究。<br />
个人技术站点:<a style="color: #0b3b8c; text-decoration: none;" href="http://www.54chen.com/">http://www.54chen.com/</a> 。可以通过电子邮件 czhttp@gmail.com 联系到他。</p>
<h2><strong>本文提及的文章</strong></h2>
<p><a href="http://dev.mysql.com/doc/refman/5.1/en/using-explain.html">http://dev.mysql.com/doc/refman/5.1/en/using-explain.html</a></p>
<p><a href="http://dev.mysql.com/doc/refman/5.1/zh/optimization.html#explain">http://dev.mysql.com/doc/refman/5.1/zh/optimization.html#explain</a></p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/architecture/mysql-explain.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jdbc socketRead0 locked 记一个Mysql的不明bug</title>
		<link>http://www.54chen.com/java-ee/jdbc-socketread0-locked-in-mind-a-mysql-unknown-bug.html</link>
		<comments>http://www.54chen.com/java-ee/jdbc-socketread0-locked-in-mind-a-mysql-unknown-bug.html#comments</comments>
		<pubDate>Thu, 07 Jan 2010 04:10:57 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.54chen.com/java-ee/jdbc-socketread0-locked-in-mind-a-mysql-unknown-bug.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>在开发人人网海量存储系统Nuclear的过程中，使用到mysql引擎，用了spring+dbcp+jdbc，在压力测试的过程中出现了问题。 在追踪java stack的过程中发现如下的问题： java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188) - locked &#60;0x00002aaab9b2b0d8&#62; (a com.mysql.jdbc.util.ReadAheadInputStream) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2494) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3005) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2938) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3481) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1416) at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2883) at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:476) at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2576) at &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>在开发人人网海量存储系统Nuclear的过程中，使用到<a href="http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html">mysql</a>引擎，用了spring+dbcp+jdbc，在压力测试的过程中出现了问题。</p>
<p>在追踪java stack的过程中发现如下的问题：</p>
<blockquote><p>java.lang.Thread.State: RUNNABLE<br />
at java.net.SocketInputStream.socketRead0(Native Method)<br />
at java.net.SocketInputStream.read(SocketInputStream.java:129)<br />
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)<br />
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)<br />
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)<br />
- locked &lt;0x00002aaab9b2b0d8&gt; (a com.mysql.jdbc.util.ReadAheadInputStream)<br />
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2494)<br />
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3005)<br />
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2938)<br />
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3481)<br />
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)<br />
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1416)<br />
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2883)<br />
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:476)<br />
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2576)<br />
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1757)<br />
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2167)<br />
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)<br />
- locked &lt;0x00002aaab9d98790&gt; (a java.lang.Object)<br />
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)<br />
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2228)<br />
- locked &lt;0x00002aaab9d98790&gt; (a java.lang.Object)<br />
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)<br />
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)<br />
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:648)<br />
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:591)<br />
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:641)<br />
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:670)<br />
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702)<br />
at com.renren.nuclear.storage.MySqlDumpEngine.getListByLeftRight(MySqlDumpEngine.java:198)</p></blockquote>
<p>其中锁住了<a href="http://www.54chen.com/memo/%e4%b8%80%e5%91%a8%e5%ba%9f%e8%af%9d%e6%b1%87%e6%80%bb%e3%80%9054chen-twitter-2009-08-22%e3%80%91.html">tcp</a>的socket，在研究无果的情况下，试着搜了一下，发现已经有人在<a href="http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html">mysql </a>bugs里提到：</p>
<p>http://bugs.mysql.com/bug.php?id=9515</p>
<p><strong>分析产生bug的原因：</strong></p>
<p><a href="http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html">mysql</a>建表的时候使用<a href="http://www.54chen.com/_linux_/%e5%8e%9f%e5%88%9b%e5%ae%9e%e6%b5%8bmysql%e6%97%b6%e9%97%b4%e5%ad%97%e6%ae%b5%e7%a9%b6%e7%ab%9f%e4%bd%bf%e7%94%a8int%e8%bf%98%e6%98%afdatetime%ef%bc%9f.html">innoDB</a>，表中有过千万的数据，每次取过多的数据，就会重现。</p>
<p>可能的原因：jdbc在做网络层的时候tcp的buffer不够所致io锁。</p>
<p><strong>最简单的解决办法：</strong></p>
<p>把原来的limit 1000改小，变成了limit 100。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/java-ee/jdbc-socketread0-locked-in-mind-a-mysql-unknown-bug.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>wordpress nginx php-cgi mysql在128m内存下的vps安装和优化手记[原创]</title>
		<link>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html</link>
		<comments>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html#comments</comments>
		<pubDate>Sun, 02 Aug 2009 07:34:49 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[架构研究]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-cgi]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.8.2 转载请注明原文链接：http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/ ] 选取CentOS，因为它是号称最安全及性能都相对较好的Linux系统。系统内存128m，系统用掉30m，有100m左右可用（如图1所示），swap已经有256M，硬盘为5G，除去系统后大约有4G可供捣腾。 图1。   首先，在空白的系统上使用下面的命令，安装gcc等一堆工具和后面php会用到的一些包： yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.8.2 转载请注明原文链接：<a href="http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/">http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/</a> ]</p>
<p>选取CentOS，因为它是号称最安全及性能都相对较好的Linux系统。系统内存128m，系统用掉30m，有100m左右可用（如图1所示），swap已经有256M，硬盘为5G，除去系统后大约有4G可供捣腾。</p>
<p><a href="http://www.54chen.com/wp-content/uploads/2009/08/1.jpg"><img class="alignleft size-full wp-image-689" title="图1" src="http://www.54chen.com/wp-content/uploads/2009/08/1.jpg" alt="" width="500" height="78" /></a><br />
图1。</p>
<p> </p>
<p>首先，在空白的系统上使用下面的命令，安装gcc等一堆工具和后面php会用到的一些包：</p>
<p><code>yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers</code></p>
<p>yum这一堆东西会有点慢，这里正好插播一下，mysql的编译在128的内存下非常慢，所以呆会儿我们会采取直接yum，php、nginx都下源码编译，经过以往的经验eAccelerator、Xcache和Zend Optimizer这三者，最好是用eAccelerator搭配Zend Optimizer能给php加速得到最佳效果，当然了，Zend Optimizer需要Zend Guard来搭配，而后者是收费的，伟大的中国人有伟大的破解。</p>
<p>我执行的时候耗时32分钟左右。</p>
<p>言归正传，继续：<br />
<code>wget http://sysoev.ru/nginx/nginx-0.7.61.tar.gz<br />
wget http://www.php.net/get/php-5.2.10.tar.gz/from/this/mirror<br />
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz<br />
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2<br />
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz [nginx rewrite使用]</code></p>
<p>【安装<a href="http://www.54chen.com/19-mysql%e6%93%8d%e4%bd%9c%e8%a6%81%e7%82%b9%e6%95%b4%e7%90%86/">MySQL</a>】<br />
<code>yum install -y mysql-server<br />
启动MySQL:<br />
service mysqld start<br />
设置mysql数据库root帐号密码:<br />
mysqladmin -u root password 'newpassword' [引号内填密码]<br />
让mysql更安全：<br />
mysql -u root -p [此时会要求你输入刚刚设置的密码，输入后回车即可]</code></p>
<p>mysql&gt; DROP DATABASE test; [删除test数据库]<br />
mysql&gt; DELETE FROM mysql.user WHERE user = ''; [删除匿名帐户]<br />
mysql&gt;DELETE FROM mysql.user WHERE password = '';[删除无密码帐户]<br />
mysql&gt; FLUSH PRIVILEGES; [重载权限]</p>
<p>【优化MySQL】<br />
此时的mysql直接吃掉20m左右的内存，如图2所示。我们要对其进行优化，关掉<a href="http://www.54chen.com/358-mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh/">innodb</a>。</p>
<p><a href="http://www.54chen.com/wp-content/uploads/2009/08/2.jpg"><img class="alignleft size-full wp-image-691" title="图2" src="http://www.54chen.com/wp-content/uploads/2009/08/2.jpg" alt="" width="499" height="170" /></a>图2。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>vi /etc/my.cnf<br />
在后面增加如下内容：</p>
<p><code>skip-innodb<br />
[mysql]<br />
no-auto-rehash</code></p>
<p>[mysqld]<br />
user = mysql<br />
port = 3306<br />
open_files_limit = 600<br />
back_log = 20<br />
max_connections = 100<br />
max_connect_errors = 200<br />
table_cache = 60<br />
external-locking = FALSE<br />
max_allowed_packet = 16M<br />
sort_buffer_size = 128K<br />
join_buffer_size = 128K<br />
thread_cache_size = 10<br />
thread_concurrency = 8<br />
query_cache_size = 0M<br />
query_cache_limit = 2M<br />
query_cache_min_res_unit = 2k<br />
default_table_type = MyISAM<br />
thread_stack = 192K<br />
transaction_isolation = READ-UNCOMMITTED<br />
tmp_table_size = 512K<br />
max_heap_table_size = 32M<br />
long_query_time = 1<br />
log_long_format<br />
server-id = 1<br />
binlog_cache_size = 2M<br />
max_binlog_cache_size = 4M<br />
max_binlog_size = 512M<br />
expire_logs_days = 7<br />
key_buffer_size = 4M<br />
read_buffer_size = 1M<br />
read_rnd_buffer_size = 2M<br />
bulk_insert_buffer_size = 2M<br />
myisam_sort_buffer_size = 4M<br />
myisam_max_sort_file_size = 10G<br />
myisam_max_extra_sort_file_size = 10G<br />
myisam_repair_threads = 1<br />
myisam_recover</p>
<p>[mysqldump]<br />
quick<br />
max_allowed_packet = 16M</p>
<p>【重启MySQL】<br />
service mysqld restart<br />
再看mysql吃掉的内存，已经降低了四分之一，如图3所示：<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/3.jpg"><img class="alignleft size-full wp-image-692" title="图3" src="http://www.54chen.com/wp-content/uploads/2009/08/3.jpg" alt="" width="500" height="170" /></a>图3。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>【安装php】<br />
首先使用yum安装上mysql的开发包，供<a href="http://www.54chen.com/490-%e5%a6%82%e4%bd%95%e7%94%a8php%e4%bb%a3%e7%a0%81%e6%b8%85%e7%a9%basquid%e7%bc%93%e5%ad%98%e4%b8%8b%e7%9a%84%e6%8c%87%e5%ae%9a%e6%96%87%e4%bb%b6/">php</a>扩展mysql使用：<br />
<code>yum -y install mysql-devel<br />
安装patch工具：<br />
yum -y install patch<br />
tar zxvf php-5.2.10.tar.gz<br />
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1<br />
cd php-5.2.10<br />
./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/usr/share/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --without-pear<br />
make &amp;&amp; make install</code><br />
把pear手动装上(这个是5.2.10的一个bug，后面可能已经打补丁了)：<br />
curl http://pear.php.net/go-pear | /opt/php/bin/php<br />
cp php.ini-dist /opt/php/etc/php.ini</p>
<p>【安装eaccelerator】<br />
<code>tar jxvf eaccelerator-0.9.5.3.tar.bz2<br />
cd eaccelerator-0.9.5.3<br />
/opt/php/bin/phpize<br />
./configure --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config<br />
make &amp;&amp; make install</code><br />
mkdir -p /opt/eaccelerator_cache<br />
vi /opt/php/etc/php.ini</p>
<p>添加下面的内容：<br />
<code>[eaccelerator]<br />
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"<br />
eaccelerator.shm_size="64"<br />
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"<br />
eaccelerator.enable="1"<br />
eaccelerator.optimizer="1"<br />
eaccelerator.check_mtime="1"<br />
eaccelerator.debug="0"<br />
eaccelerator.filter=""<br />
eaccelerator.shm_max="0"<br />
eaccelerator.shm_ttl="3600"<br />
eaccelerator.shm_prune_period="3600"<br />
eaccelerator.shm_only="0"<br />
eaccelerator.compress="1"<br />
eaccelerator.compress_level="9"</code></p>
<p> </p>
<p>【安装<a href="http://www.54chen.com/157-php%e4%bb%a3%e7%a0%81%e7%9a%84%e4%bc%98%e4%b8%8e%e5%8a%a3/">Zend</a> Optimizer】<br />
要去zend.com上注册用户名后进download页面下载，这里太弱智了，不知道zend是否有专门的产品人员，这种注册下载有什么意义，只是一堆死账号而已。<br />
下载ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz<br />
<code>tar -zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz<br />
cd ZendOptimizer-3.3.3-linux-glibc23-i386<br />
./install</code></p>
<p>运行过程中会要求你写些安装路径啥的，照着写就是。<br />
如果出现类似下面的错误：<br />
./install-tty: line 139: ./php: cannot execute binary file<br />
那说明你下错了包了，这种情况是因为你32位的系统下了64位的包或者是反过来。</p>
<p>【安装nginx】<br />
<code>tar -zxvf pcre-7.9.tar.gz<br />
cd pcre-7.9<br />
./configure<br />
make &amp;&amp; make install<br />
cd ..</code></p>
<p>tar zxvf nginx-0.7.61.tar.gz<br />
cd nginx-0.7.61<br />
./configure --user=www --group=www --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module<br />
make &amp;&amp; make install</p>
<p>增加www用户：<br />
groupadd www<br />
useradd -g www www</p>
<p>【优化php\nginx】<br />
1.优化php-fpm.conf<br />
<code>vi /opt/php/etc/php-fpm.conf<br />
修改log level为error:<br />
error<br />
修改max_children:<br />
5<br />
修改listen_address为unix socket方式运行：<br />
/tmp/php-cgi.sock</code></p>
<p>2.优化nginx.conf<br />
vi /opt/nginx/conf/nginx.conf<br />
在events中增加：<br />
<code>use epoll;<br />
在http中增加下面的代码，打开gzip：<br />
gzip on;<br />
gzip_min_length 1k;<br />
gzip_buffers 4 16k;<br />
gzip_http_version 1.0;<br />
gzip_comp_level 2;<br />
gzip_types text/plain application/x-javascript text/css application/xml;<br />
gzip_vary on;<br />
在使用php的server中使用unix socket通信方式：<br />
fastcgi_pass unix:/tmp/php-cgi.sock;</code></p>
<p>【设置开机启动】<br />
/sbin/chkconfig --add mysqld [在服务清单中添加mysql服务]<br />
/sbin/chkconfig mysqld on [设置mysql服务开机启动]</p>
<p>vi /etc/rc.locale<br />
加入两行：<br />
/opt/php/sbin/php-fpm start<br />
/opt/nginx/sbin/nginx</p>
<p>【误区提示】<br />
XEN更像物理服务器，会尽量把剩余的内存当成buffer和cache，所以看到下图的时候不要惊慌，其实内存都在cache里了。<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/x.jpg"><img class="alignleft size-full wp-image-693" title="图4" src="http://www.54chen.com/wp-content/uploads/2009/08/x.jpg" alt="" width="500" height="94" /></a>图4</p>
<p> </p>
<p> </p>
<p>【wordpress专项优化】<br />
使用wp-super-cache插件，将页面生成html，省去php的开销，性能有提升。<br />
对照access log，刷新页面，看堵在什么地方</p>
<p>【几个建议】<br />
合并css js个数 并且压缩 速度提升明显<br />
wordpress没有任何插件的时候，效率是很不错的，但是有些不负责任的插件会导致整体看起来很慢，下面是一些常用的插件的问题：<br />
1.twitter tools插件：用来从后端取twitter数据的，这个插件搞了一个js一个css在head里，并且都是通过php生成的，两个php请求，让首页很慢。建议去掉（可能会影响自动化？没来得及分析细节）。<br />
2.wp-spamfree插件：用来做antispam的，这是一个动态生成的js，不知道为什么非常慢。建议换别的插件。</p>
<p>【结果展示】<br />
在完成上述一系列的操作后，http://54chen.com 我是陈科学院的打开速度已经非常迅速了，基本上一秒钟就能全部显示。内存还有40m空闲，如图5所示：<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/5.jpg"><img class="alignleft size-full wp-image-694" title="图5" src="http://www.54chen.com/wp-content/uploads/2009/08/5.jpg" alt="" width="500" height="79" /></a>图5</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html/feed</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>[原创][实测]MySQL时间字段究竟使用INT还是DateTime？</title>
		<link>http://www.54chen.com/_linux_/%e5%8e%9f%e5%88%9b%e5%ae%9e%e6%b5%8bmysql%e6%97%b6%e9%97%b4%e5%ad%97%e6%ae%b5%e7%a9%b6%e7%ab%9f%e4%bd%bf%e7%94%a8int%e8%bf%98%e6%98%afdatetime%ef%bc%9f.html</link>
		<comments>http://www.54chen.com/_linux_/%e5%8e%9f%e5%88%9b%e5%ae%9e%e6%b5%8bmysql%e6%97%b6%e9%97%b4%e5%ad%97%e6%ae%b5%e7%a9%b6%e7%ab%9f%e4%bd%bf%e7%94%a8int%e8%bf%98%e6%98%afdatetime%ef%bc%9f.html#comments</comments>
		<pubDate>Mon, 27 Apr 2009 11:05:07 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[INT vs DateTime]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/%e5%8e%9f%e5%88%9b%e5%ae%9e%e6%b5%8bmysql%e6%97%b6%e9%97%b4%e5%ad%97%e6%ae%b5%e7%a9%b6%e7%ab%9f%e4%bd%bf%e7%94%a8int%e8%bf%98%e6%98%afdatetime%ef%bc%9f.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.4.27 转载请注明原文链接：http://www.54chen.com/c/560 ] 环境： Windows XP PHP Version 5.2.9 MySQL Server 5.1 第一步、创建一个表date_test（非定长、int时间） CREATE TABLE `test`.`date_test` ( `id` INT NOT NULL AUTO_INCREMENT , `start_time` INT NOT NULL , `some_content` VARCHAR( 255 ) NOT NULL , PRIMARY KEY &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.4.27 转载请注明原文链接：<a href="../c/560">http://www.54chen.com/c/560</a> ]</p>
<p>环境：<br />
Windows XP<br />
<a href="http://www.54chen.com/c/441">PHP </a>Version 5.2.9<br />
MySQL Server 5.1</p>
<p>第一步、创建一个表date_test（非定长、int时间）</p>
<p>CREATE TABLE `test`.`date_test` (<br />
`id` INT NOT NULL AUTO_INCREMENT ,<br />
`start_time` INT NOT NULL ,<br />
`some_content` VARCHAR( 255 ) NOT NULL ,<br />
PRIMARY KEY ( `id` )<br />
) ENGINE = InnoDB;</p>
<p>第二步、创建第二个表date_test2（定长、int时间）</p>
<p>CREATE TABLE `test`.`date_test2` (<br />
`id` INT NOT NULL AUTO_INCREMENT ,<br />
`start_time` INT NOT NULL ,<br />
`some_content` CHAR( 255 ) NOT NULL ,<br />
PRIMARY KEY ( `id` )<br />
) ENGINE = InnoDB;</p>
<p>第三步、创建第三个<a href="http://www.54chen.com/c/539">表</a>date_test3（varchar、datetime时间）</p>
<p>CREATE TABLE `test`.`date_test3` (<br />
`id` INT NOT NULL AUTO_INCREMENT ,<br />
`start_time` DATETIME NOT NULL ,<br />
`some_content` VARCHAR( 255 ) NOT NULL ,<br />
PRIMARY KEY ( `id` )<br />
) ENGINE = InnoDB;</p>
<p>第四步、创建第四个表date_test3（char、datetime时间）</p>
<p>CREATE TABLE `test`.`date_test4` (<br />
`id` INT NOT NULL AUTO_INCREMENT ,<br />
`start_time` DATETIME NOT NULL ,<br />
`some_content` CHAR( 255 ) NOT NULL ,<br />
PRIMARY KEY ( `id` )<br />
) ENGINE = InnoDB;</p>
<p>ok，现在我们开始做<a href="http://www.54chen.com/c/45">测试</a>，环境是php，先向各个表插入一百万条数据。插入的时候分200次，每次进库5000条。</p>
<p>表一执行记录：页面运行时间: 26.5997889042 秒，插入的时候发现一个有趣的现象：SELECT count( id ) FROM `date_test` WHERE 1 的结果是100w,而直接select * from `date_test`却是1,000,374条结果。（后来看到这是一个可能接近的值，请参看MySQL FAQ 3.11）。<br />
表二执行记录：页面运行时间: 62.3908278942 秒，这次记录是1,000,066条。<br />
表三执行记录：页面运行时间: 30.2576560974 秒，这次的是1,000,224条。<br />
表四执行记录：页面运行时间: 67.5393900871 秒，这次的是：1,000,073条。</p>
<p>现在把四个表的start_time字段一一加上索引。</p>
<p>测试四个表的更新，分别update 100条记录，并记录时间:<br />
表一：页面运行时间: 2.62180089951 秒（非定长，int时间）<br />
表二：页面运行时间: 2.5475358963 秒（定长，int时间）<br />
表三：页面运行时间: 2.45077300072 秒（varchar,datetime时间）<br />
表四：页面运行时间: 2.82798409462 秒（char,datetime时间）</p>
<p>测试四个表的读取，分别select 100条随机记录，以主键id为条件查询，并记录时间：<br />
表一：页面运行时间: 0.382651090622 秒（非定长，int时间）<br />
表二：页面运行时间: 0.542181015015 秒（定长，int时间）<br />
表三：页面运行时间: 0.334048032761 秒（varchar,datetime时间）<br />
表四：页面运行时间: 0.506206989288 秒（char,datetime时间）</p>
<p>测试四个表的读取，分别select 10条随机记录，以star_time为条件查询，并记录时间：<br />
表一：页面运行时间: 30.1972880363 秒（非定长，int时间）<br />
表二：页面运行时间: 65.1926910877 秒（定长，int时间）<br />
表三：页面运行时间: 39.7210869789 秒（varchar,datetime时间）<br />
表四：页面运行时间: 70.4632740021 秒（char,datetime时间）</p>
<p>因为量比较小，所以我们默认即使是微小的变化，也是有意义的。</p>
<p>结论：</p>
<p><strong>大数据量下，如果存在大量的select * from table where 时间&gt;XX这样的查询，在MySQL5.1时使用int换datetime是有意义的。</strong></p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/%e5%8e%9f%e5%88%9b%e5%ae%9e%e6%b5%8bmysql%e6%97%b6%e9%97%b4%e5%ad%97%e6%ae%b5%e7%a9%b6%e7%ab%9f%e4%bd%bf%e7%94%a8int%e8%bf%98%e6%98%afdatetime%ef%bc%9f.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>多台slave的mysql replication的配置</title>
		<link>http://www.54chen.com/_linux_/e5-a4-9a-e5-8f-b0slave-e7-9a-84mysql-replication-e7-9a-84-e9-85-8d-e7-bd-ae.html</link>
		<comments>http://www.54chen.com/_linux_/e5-a4-9a-e5-8f-b0slave-e7-9a-84mysql-replication-e7-9a-84-e9-85-8d-e7-bd-ae.html#comments</comments>
		<pubDate>Fri, 16 Jan 2009 02:51:14 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[slave]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/e5-a4-9a-e5-8f-b0slave-e7-9a-84mysql-replication-e7-9a-84-e9-85-8d-e7-bd-ae.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br> 5.1.24版本的配置请看：http://www.masalife.com/archives/173 一、先修改服务器的配置文件        1、Master服务器配置简单，修改my.cnf为:        server-id       = 1 log-bin set-variable=binlog-ignore-db=mysql 2、slave1的配置加入 server-id       = 2 master-host = 172.16.20.135 master-user = rep master-password = cnrep master-port = 3306 log-bin set-variable=replicate-ignore-db=mysql set-variable=replicate-do-db=AliSMS set-variable=replicate-do-db=lcd set-variable=replicate-do-db=loginmanager set-variable=replicate-do-db=samis set-variable=replicate-do-db=sareport set-variable=replicate-do-db=syslog set-variable=replicate-do-db=web_speed log-slave-updates 3、slave2服务器的配置 server-id       = 3 &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p> 5.1.24版本的配置请看：http://www.masalife.com/archives/173</p>
<p align="center"><strong><br />
</strong></p>
<p>一、先修改服务器的配置文件</p>
<p>       1、Master服务器配置简单，修改my.cnf为:</p>
<p>       server-id       = 1</p>
<p>log-bin</p>
<p>set-variable=binlog-ignore-db=mysql</p>
<p>2、slave1的配置加入</p>
<p>server-id       = 2</p>
<p>master-host = 172.16.20.135</p>
<p>master-user = rep</p>
<p>master-password = cnrep</p>
<p>master-port = 3306</p>
<p>log-bin</p>
<p>set-variable=replicate-ignore-db=mysql</p>
<p>set-variable=replicate-do-db=AliSMS</p>
<p>set-variable=replicate-do-db=lcd</p>
<p>set-variable=replicate-do-db=loginmanager</p>
<p>set-variable=replicate-do-db=samis</p>
<p>set-variable=replicate-do-db=sareport</p>
<p>set-variable=replicate-do-db=syslog</p>
<p>set-variable=replicate-do-db=web_speed</p>
<p>log-slave-updates</p>
<p>3、slave2服务器的配置</p>
<p>server-id       = 3</p>
<p>master-host = 172.16.20.3</p>
<p>master-user = rep1</p>
<p>master-password = cnrep</p>
<p>master-port = 3306</p>
<p>set-variable=replicate-ignore-db=mysql</p>
<p>set-variable=replicate-do-db=AliSMS</p>
<p>set-variable=replicate-do-db=lcd</p>
<p>set-variable=replicate-do-db=loginmanager</p>
<p>set-variable=replicate-do-db=samis</p>
<p>set-variable=replicate-do-db=sareport</p>
<p>set-variable=replicate-do-db=syslog</p>
<p>set-variable=replicate-do-db=web_speed</p>
<p> </p>
<p>二、重启master数据库</p>
<p> </p>
<p>三、然后锁定master数据库的表：</p>
<p>mysql&gt;FLUSH TABLES WITH READ LOCK;</p>
<p>四、在master数据库中添加用于slave1同步的用户，并赋予相关权限：</p>
<p>mysql&gt;GRANT REPLICATION SLAVE ON *.* TO rep@sa_cfengine1 IDENTIFIED BY 'cnrep';</p>
<p>mysql&gt;GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO rep@sa_cfengine1 IDENTIFIED BY 'cnrep';</p>
<p> </p>
<p>五、在slave1数据库中添加用于slave2同步的用户，并赋予相关权限：</p>
<p>mysql&gt;GRANT REPLICATION SLAVE ON *.* TO rep1@sa_cfengine2 IDENTIFIED BY 'cnrep';</p>
<p>mysql&gt;GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO rep1@sa_cfengine2 IDENTIFIED BY 'cnrep';</p>
<p> </p>
<p>六、同步数据库：</p>
<p>方法很多，可以打包之后scp，再解压，由于sa_cfengine1到mysql master服务器通道打通了，切sa_cfengine2到sa_cfengine1通道也打了，故直接scp整个数据库目录即可。</p>
<p>注意：此时要注意删除同步过来的日志文件，最好把与数据库无关的文件全删除（可以将非目录的文件全删了）。</p>
<p> </p>
<p>七、重启salve1的mysql，起来之后锁定表</p>
<p> </p>
<p>八、重启slave2的mysql，然后先后给slave1和master服务器的mysql表解锁</p>
<p>mysql&gt; UNLOCK TABLES；</p>
<p> </p>
<p>九、分别登录slave1和slave2的mysql，查看同步状态：</p>
<pre>        mysql&gt;SHOW SLAVE STATUS\G</pre>
<p>*************************** 1. row ***************************</p>
<p>             Slave_IO_State: Waiting for master to send event</p>
<p>                Master_Host: 172.16.20.135</p>
<p>                Master_User: rep</p>
<p>                Master_Port: 3306</p>
<p>              Connect_Retry: 60</p>
<p>            Master_Log_File: mysql-bin.000051</p>
<p>        Read_Master_Log_Pos: 13856842</p>
<p>             Relay_Log_File: sa_cfengine1-relay-bin.000013</p>
<p>              Relay_Log_Pos: 624419</p>
<p>      Relay_Master_Log_File: mysql-bin.000051</p>
<p><span style="color: #ff0000;">          </span><strong><span style="color: #ff0000;"> Slave_IO_Running: Yes</span></strong></p>
<p><strong><span style="color: #ff0000;">          Slave_SQL_Running: Yes</span></strong></p>
<p>            Replicate_Do_DB: AliSMS,lcd,loginmanager,samis,sareport,syslog,web_speed</p>
<p>        Replicate_Ignore_DB: mysql,mysql</p>
<p>         Replicate_Do_Table:</p>
<p>     Replicate_Ignore_Table:</p>
<p>    Replicate_Wild_Do_Table:</p>
<p>Replicate_Wild_Ignore_Table:</p>
<p>                 Last_Errno: 0</p>
<p>                 Last_Error:</p>
<p>               Skip_Counter: 0</p>
<p>        Exec_Master_Log_Pos: 13856842</p>
<p>            Relay_Log_Space: 624419</p>
<p>            Until_Condition: None</p>
<p>             Until_Log_File:</p>
<p>              Until_Log_Pos: 0</p>
<p>         Master_SSL_Allowed: No</p>
<p>         Master_SSL_CA_File:</p>
<p>         Master_SSL_CA_Path:</p>
<p>            Master_SSL_Cert:</p>
<p>          Master_SSL_Cipher:</p>
<p>             Master_SSL_Key:</p>
<p>      Seconds_Behind_Master: 0</p>
<p>1 row in set (0.01 sec)</p>
<p>注意标注为红色的地方，两个都是yes说明一切正常，否则要检查原因，可以看error log查找原因后做相应的处理。</p>
<p> </p>
<p>十、测试：</p>
<p>       在master数据库中update在同步列表中的一个表的一个字段，如果slave服务器的做相应改变，则测试用过。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/e5-a4-9a-e5-8f-b0slave-e7-9a-84mysql-replication-e7-9a-84-e9-85-8d-e7-bd-ae.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>MySQL的性能调优工具：比mysqlreport更方便的tuning-primer.sh</title>
		<link>http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html</link>
		<comments>http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html#comments</comments>
		<pubDate>Mon, 22 Dec 2008 01:43:08 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>Sundry MySQL提供的脚本相比mysqlreport更进一步：除了报表还进一步提供了修改建议。安装和使用非常简单： wget http://www.day32.com/MySQL/tuning-primer.sh chmod +x tuning-primer.sh ./tuning-primer.sh 和mysqlreport一样，tuning-primer.sh也支持.my.cnf [client] user = USERNAME password = PASSWORD socket = /tmp/mysql.sock   样例输出：在终端上按照问题重要程度分别用黄色/红色字符标记问题 -- MYSQL PERFORMANCE TUNING PRIMER -- - By: Matthew Montgomery -   MySQL Version 5.0.45 i686 Uptime = 19 days &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><div class="entry-body" style="clear: both;">
<p style="margin-top: 10px; margin-bottom: 10px;">Sundry MySQL提供的脚本相比mysqlreport更进一步：除了报表还进一步提供了修改建议。安装和使用非常简单：</p>
<blockquote style="margin-top: 10px; margin-bottom: 10px;"><p>wget<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://www.day32.com/MySQL/tuning-primer.sh">http://www.day32.com/MySQL/tuning-primer.sh</a><br />
chmod +x tuning-primer.sh<br />
./tuning-primer.sh</p></blockquote>
<p>和mysqlreport一样，tuning-primer.sh也支持.my.cnf</p>
<blockquote style="margin-top: 10px; margin-bottom: 10px;"><p>[client]<br />
user = USERNAME<br />
password = PASSWORD<br />
socket = /tmp/mysql.sock</p></blockquote>
<p style="margin-top: 10px; margin-bottom: 10px;"> </p>
<p style="margin-top: 10px; margin-bottom: 10px;">样例输出：在终端上按照问题重要程度分别用黄色/红色字符标记问题</p>
<blockquote style="margin-top: 10px; margin-bottom: 10px;"><p>-- MYSQL PERFORMANCE TUNING PRIMER --<br />
- By: Matthew Montgomery -</p>
<p style="margin-top: 10px; margin-bottom: 10px;"> </p>
<p style="margin-top: 10px; margin-bottom: 10px;">MySQL Version 5.0.45 i686</p>
<p style="margin-top: 10px; margin-bottom: 10px;">Uptime = 19 days 8 hrs 32 min 54 sec<br />
Avg. qps = 0<br />
Total Questions = 264260<br />
Threads Connected = 1</p>
<p style="margin-top: 10px; margin-bottom: 10px;">Server has been running for over 48hrs.<br />
It should be safe to follow these recommendations</p>
<p style="margin-top: 10px; margin-bottom: 10px;">To find out more information on how each of these<br />
runtime variables effects performance visit:</p>
<p>http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html</p>
<p>Visit http://www.mysql.com/products/enterprise/advisors.html<br />
for info about MySQL's Enterprise Monitoring and Advisory Service</p>
<p style="margin-top: 10px; margin-bottom: 10px;">SLOW QUERIES<br />
The slow query log is NOT enabled.<br />
Current long_query_time = 10 sec.<br />
You have 0 out of 264274 that take longer than 10 sec. to complete<br />
Your long_query_time may be too high, I typically set this under 5 sec.</p>
<p style="margin-top: 10px; margin-bottom: 10px;">BINARY UPDATE LOG<br />
The binary update log is NOT enabled.<br />
You will not be able to do point in time recovery<br />
See http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html</p>
<p style="margin-top: 10px; margin-bottom: 10px;">WORKER THREADS<br />
Current thread_cache_size = 0<br />
Current threads_cached = 0<br />
Current threads_per_sec = 1<br />
Historic threads_per_sec = 0<br />
Your thread_cache_size is fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">MAX CONNECTIONS<br />
Current max_connections = 100<br />
Current threads_connected = 1<br />
Historic max_used_connections = 33<br />
The number of used connections is 33% of the configured maximum.<br />
Your max_connections variable seems to be fine.</p>
<p style="margin-top: 10px; margin-bottom: 10px;">MEMORY USAGE<br />
Max Memory Ever Allocated : 96 M<br />
Configured Max Per-thread Buffers : 268 M<br />
Configured Max Global Buffers : 7 M<br />
Configured Max Memory Limit : 276 M<br />
Physical Memory : 1.97 G<br />
Max memory limit seem to be within acceptable norms</p>
<p style="margin-top: 10px; margin-bottom: 10px;">KEY BUFFER<br />
Current MyISAM index space = 8 M<br />
Current key_buffer_size = 7 M<br />
Key cache miss rate is 1 : 1817<br />
Key buffer fill ratio = 6.00 %<br />
Your key_buffer_size seems to be too high.<br />
Perhaps you can use these resources elsewhere</p>
<p style="margin-top: 10px; margin-bottom: 10px;">QUERY CACHE<br />
Query cache is supported but not enabled<br />
Perhaps you should set the query_cache_size</p>
<p style="margin-top: 10px; margin-bottom: 10px;">SORT OPERATIONS<br />
Current sort_buffer_size = 2 M<br />
Current read_rnd_buffer_size = 256 K<br />
Sort buffer seems to be fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">JOINS<br />
Current join_buffer_size = 132.00 K<br />
You have had 0 queries where a join could not use an index properly<br />
Your joins seem to be using indexes properly</p>
<p style="margin-top: 10px; margin-bottom: 10px;">OPEN FILES LIMIT<br />
Current open_files_limit = 1024 files<br />
The open_files_limit should typically be set to at least 2x-3x<br />
that of table_cache if you have heavy MyISAM usage.<br />
Your open_files_limit value seems to be fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">TABLE CACHE<br />
Current table_cache value = 64 tables<br />
You have a total of 125 tables<br />
You have 64 open tables.<br />
Current table_cache hit rate is 9%, while 100% of your table cache is in use<br />
<strong>You should probably increase your table_cache<br />
</strong><br />
TEMP TABLES<br />
Current max_heap_table_size = 16 M<br />
Current tmp_table_size = 32 M<br />
Of 564 temp tables, 6% were created on disk<br />
Effective in-memory tmp_table_size is limited to max_heap_table_size.<br />
Created disk tmp tables ratio seems fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">TABLE SCANS<br />
Current read_buffer_size = 128 K<br />
Current table scan ratio = 1 : 1<br />
read_buffer_size seems to be fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">TABLE LOCKING<br />
Current Lock Wait ratio = 0 : 264392<br />
Your table locking seems to be fine</p></blockquote>
<p style="margin-top: 10px; margin-bottom: 10px;"> </p>
<p style="margin-top: 10px; margin-bottom: 10px;">更有用是作者总结的处理MySQL性能问题处理的优先级：尤其是头3条，基本上可以解决大部分瓶颈问题的原因。<br />
# Slow Query Log 慢查询 尤其是like操作，性能杀手，轻易不要使用，让全文索引交给<a style="color: #3165ce; text-decoration: underline;" href="http://www.chedong.com/tech/lucene.html">Lucene</a>或者利用Tag机制减少like操作；<br />
# Max Connections 并发连接数：一个MySQL deamon缺省最大连接数是100，调到更高只是为了出现问题是给我们更多的缓冲时间而不是任其一直处于那么高的状态，并发连接数类似于等候大厅：当等候人数过多的时候，一味扩大等候厅不是根本解决问题的办法，提高业务的处理速度，多开几个窗口才是更好的解决方法；我的经验就是<a style="color: #3165ce; text-decoration: underline;" href="http://www.chedong.com/blog/archives/000945.html">超过100： 数据就要想办法（镜像或者分片）分布到更多Deamon上</a>；<br />
# Worker Threads：<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://jeremy.zawodny.com/blog/archives/000173.html">Jeremy Zawondy 曾在部落格上說到：Thread caching</a><span class="Apple-converted-space"> </span>並不是我們最需要關心的問題，但當你解決了所有其他更嚴重的問題之後，它就會是最嚴重的問題。(thread caching really wasn't the worst of our problems. But it became the worst after we had fixed all the bigger ones.)<br />
# Key Buffer<span class="Apple-converted-space"> </span><br />
# Query Cache<span class="Apple-converted-space"> </span><br />
# Sort Buffer<span class="Apple-converted-space"> </span><br />
# Joins<span class="Apple-converted-space"> </span><br />
# Temp Tables 临时表<br />
# Table (Open &amp; Definition) Cache 表缓存；<br />
# Table Locking 表锁定<br />
# Table Scans (read_buffer)<span class="Apple-converted-space"> </span><br />
# Innodb Status</p>
</div>
<div id="more" class="entry-more" style="clear: both;">
<p style="margin-top: 10px; margin-bottom: 10px;">其他一些工具：<span class="Apple-converted-space"> </span><br />
1<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://jeremy.zawodny.com/mysql/mytop/">mytop</a>： 一个top like的show processlist;<br />
2 使用cacti做MySQL的监控：推荐<a style="color: #3165ce; text-decoration: underline;" href="http://code.google.com/p/mysql-cacti-templates/">配置模板</a>；<br />
3 把binlog导出成文本和slowquery的格式几乎是一样的，调用mysqlslowquery脚本分析，有时候也会有意外收获；</p>
<p style="margin-top: 10px; margin-bottom: 10px;">谢谢 oldplantegg 补充：<br />
<a style="color: #3165ce; text-decoration: underline;" href="http://hackmysql.com/mysqlsla">mysqlsla</a>(<a style="color: #3165ce; text-decoration: underline;" href="http://hackmysql.com/">hackmysql.com</a>推出的一款日志分析工具该网站还维护了，mysqlreport,<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://hackmysql.com/mysqlidxchk">mysqlidxchk</a><span class="Apple-converted-space"> </span>等比较实用的mysql工具)能够分析slow query 和binlog等，这样就不用将binlog导出来了.</p>
<p style="margin-top: 10px; margin-bottom: 10px;">from:http://www.chedong.com/blog/archives/001451.html</p>
</div>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MySQL中各种字段的取值范围</title>
		<link>http://www.54chen.com/php-tech/mysql-in-a-variety-of-fields-in-the-range.html</link>
		<comments>http://www.54chen.com/php-tech/mysql-in-a-variety-of-fields-in-the-range.html#comments</comments>
		<pubDate>Wed, 22 Mar 2006 14:44:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[字段类型]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/mysql-in-a-variety-of-fields-in-the-range.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>TINYINT -128 - 127   TINYINT UNSIGNED 0 - 255 SMALLINT -32768 - 32767 SMALLINT UNSIGNED 0 - 65535 MEDIUMINT -8388608 - 8388607 MEDIUMINT UNSIGNED 0 - 16777215 INT 或 INTEGER -2147483648 - 2147483647 INT UNSIGNED 或 INTEGER UNSIGNED 0 &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>TINYINT<br />
-128 - 127</p>
<p> </p>
<p>TINYINT UNSIGNED<br />
0 - 255</p>
<p>SMALLINT<br />
-32768 - 32767</p>
<p>SMALLINT UNSIGNED<br />
0 - 65535</p>
<p>MEDIUMINT<br />
-8388608 - 8388607</p>
<p>MEDIUMINT UNSIGNED<br />
0 - 16777215</p>
<p>INT 或 INTEGER<br />
-2147483648 - 2147483647</p>
<p>INT UNSIGNED 或 INTEGER UNSIGNED<br />
0 - 4294967295</p>
<p>BIGINT<br />
-9223372036854775808 - 9223372036854775807</p>
<p>BIGINT UNSIGNED<br />
0 - 18446744073709551615</p>
<p>FLOAT<br />
-3.402823466E+38 - -1.175494351E-38<br />
0<br />
1.175494351E-38 - 3.402823466E+38</p>
<p>DOUBLE 或 DOUBLE PRECISION 或 REAL<br />
-1.7976931348623157E+308 - -2.2250738585072014E-308<br />
0<br />
2.2250738585072014E-308 - 1.7976931348623157E+308</p>
<p>DECIMAL[(M,[D])] 或 NUMERIC(M,D)<br />
由M(整个数字的长度,包括小数点,小数点左边的位数,小数点右边的位数,但不包括负号)和D(小数点右边的位数)来决定,M缺省为10,D缺省为0</p>
<p>DATE<br />
1000-01-01 - 9999-12-31</p>
<p>DATETIME<br />
1000-01-01 00:00:00 - 9999-12-31 23:59:59</p>
<p>TIMESTAMP<br />
1970-01-01 00:00:00 - 2037年的某天(具体是哪天我也不知道,呵呵)</p>
<p>TIME<br />
-838:59:59' to 838:59:59</p>
<p>YEAR[(2|4)]<br />
缺省为4位格式,4位格式取值范围为1901 - 2155,0000,2位格式取值范围为70-69(1970-2069)</p>
<p>CHAR(M) [BINARY] 或 NCHAR(M) [BINARY]<br />
M的范围为1 - 255,如果没有BINARY项,则不分大小写,NCHAR表示使用缺省的字符集.在数据库中以空格补足,但在取出来时末尾的空格将自动去掉.</p>
<p>[NATIONAL] VARCHAR(M) [BINARY]<br />
M的范围为1 - 255.在数据库中末尾的空格将自动去掉.</p>
<p>TINYBLOB 或 TINYTEXT<br />
255(2^8-1)个字符</p>
<p>BLOB 或 TEXT<br />
65535(2^16-1)个字符</p>
<p>MEDIUMBLOB 或 MEDIUMTEXT<br />
16777215 (2^24-1)个字符</p>
<p>LONGBLOB 或 LONGTEXT<br />
4294967295 (2^32-1)个字符</p>
<p>ENUM('value1','value2',...)<br />
可以总共有65535个不同的值</p>
<p>SET('value1','value2',...)<br />
最多有64个成员</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/mysql-in-a-variety-of-fields-in-the-range.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

