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

<channel>
	<title>MySQL实践积累</title>
	<atom:link href="http://dbahacker.com/feed" rel="self" type="application/rss+xml" />
	<link>http://dbahacker.com</link>
	<description></description>
	<lastBuildDate>Thu, 17 May 2012 03:59:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Find out the difference between Com_Select and InnoDB_rows_read</title>
		<link>http://dbahacker.com/mysql/find-out-the-difference-between-com_select-and-innodb_rows_read</link>
		<comments>http://dbahacker.com/mysql/find-out-the-difference-between-com_select-and-innodb_rows_read#comments</comments>
		<pubDate>Thu, 17 May 2012 03:57:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL InnoDB]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=236</guid>
		<description><![CDATA[This morning  one MySQL cluster ( 4 Master ,4 Slave) , one mysql server ‘s response time raises up. The raid config of the server Adapter 0 -- Virtual Drive Information: Virtual Drive: 0 (Target Id: 0) Name : RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0 Size : 99.999 GB State : Optimal Strip [...]]]></description>
			<content:encoded><![CDATA[<p>This morning  one MySQL cluster ( 4 Master ,4 Slave) , one mysql server ‘s response time raises up.</p>
<p>The raid config of the server</p>
<pre class="brush: sql; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :
RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0
Size                : 99.999 GB
State               : Optimal
Strip Size          : 64 KB
Number Of Drives per span:2
Span Depth          : 6
Default Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disabled
Encryption Type     : None

Virtual Drive: 1 (Target Id: 1)
Name                :
RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0
Size                : 1.533 TB
State               : Optimal
Strip Size          : 64 KB
Number Of Drives per span:2
Span Depth          : 6
Default Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disabled
Encryption Type     : None</pre>
<p>The pressure tends of this server</p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/05/image.png"><img style="display: inline; border-width: 0px;" title="image" src="http://dbahacker.com/wp-content/uploads/2012/05/image_thumb.png" alt="image" width="630" height="241" border="0" /></a></p>
<p>The first trend is MySQL Com_select , the second trend picture is MySQL InnoDB_rows_read. You can find out that the InnoDB_rows_read is larger than the counter of Com_Select.</p>
<p>At the beginng , it makes me confused  that  why the result of innodb_rows_read is bigger than com_select.</p>
<p>And what’s more , iostat tells me that disk is very busy and the avg response time is over 5ms. Yes, Response time is not ideal.</p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/05/image1.png"><img style="display: inline; border: 0px;" title="image" src="http://dbahacker.com/wp-content/uploads/2012/05/image_thumb1.png" alt="image" width="795" height="198" border="0" /></a></p>
<p>Finally , i observe the running sql in MySQL.</p>
<p>I found that a large number of this  sql is running</p>
<pre class="brush: sql; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">SELECT id, user_id, subscribe_id, twoway, group_ids, gmt_create, gmt_modified
FROM table_0485
WHERE user_id =376297445
ORDER BY gmt_create DESC
LIMIT 0 , 2000</pre>
<p>What’s the problem of this sql?</p>
<p>1. It is query 2000 rows from InnoDB, if we have 100 sql like this is running, the innodb_rows_read = 100*2000;</p>
<p>2. the column user_id is not necessary to select once again, because we have post the user_id . We can redure the traffic after remove user_id,just like this “SELECT id, subscribe_id, twoway, group_ids, gmt_create, gmt_modified ”</p>
<p>&nbsp;</p>
<p>So , return to our topic “<strong>Find out the difference between Com_Select and InnoDB_rows_read</strong>”</p>
<p>Right, if we have some query that need over thounds row, although the com_select is little, but the InnoDB_rows_read may is large.</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/find-out-the-difference-between-com_select-and-innodb_rows_read/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[InnoDB]Truncate table difference between InnoDB build-in and InnoDB Plugin-in</title>
		<link>http://dbahacker.com/mysql/innodbtruncate-table-difference-between-innodb-build-in-and-innodb-plugin-in</link>
		<comments>http://dbahacker.com/mysql/innodbtruncate-table-difference-between-innodb-build-in-and-innodb-plugin-in#comments</comments>
		<pubDate>Wed, 16 May 2012 09:26:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[InnoDB-Plugin]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=227</guid>
		<description><![CDATA[MySQL(5.1.37) InnoDB Build-in root@(none) 04:55:17&#62; SHOW PLUGINS; +------------+--------+----------------+---------+---------+ &#124; Name &#124; Status &#124; Type &#124; Library &#124; License &#124; +------------+--------+----------------+---------+---------+ &#124; binlog &#124; ACTIVE &#124; STORAGE ENGINE &#124; NULL &#124; GPL &#124; &#124; partition &#124; ACTIVE &#124; STORAGE ENGINE &#124; NULL &#124; GPL &#124; &#124; CSV &#124; ACTIVE &#124; STORAGE ENGINE &#124; NULL &#124; GPL [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL(5.1.37) InnoDB Build-in </p>
<pre class="brush: sql; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">root@(none) 04:55:17&gt; SHOW PLUGINS;
+------------+--------+----------------+---------+---------+
| Name       | Status | Type           | Library | License |
+------------+--------+----------------+---------+---------+
| binlog     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| partition  | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| CSV        | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| MEMORY     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| InnoDB     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| MyISAM     | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL    | GPL     |
+------------+--------+----------------+---------+---------+
7 rows in set (0.00 sec)</pre>
<p>How Can we certify we using InnoDB Plugin, you just need run “show plugins” ,if you see the result like above, it is.</p>
</p>
<p>When we truncate one table . </p>
<pre class="brush: sql; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">[MM-Writable@mysqldb /u01/mysql/data/db_02]
$du -sh db.ibd
773M    db.ibd

root@db_02 05:08:55&amp;gt;select count(*) from db;
+----------+
| count(*) |
+----------+
|  1410879 |
+----------+
1 row in set (0.38 sec) 

root@db_02 05:08:59&amp;gt;truncate table db;
Query OK, 0 rows affected (0.08 sec) 

root@db_02 05:09:05&amp;gt;select count(*) from db;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)</pre>
<p>&#160;</p>
<p>After we truncate the table “db”, we found that the total number of the table is zero. But the file is still use the space</p>
<pre class="brush: sql; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">$du -sh * | grep db

12K     db.frm
773M    db.ibd</pre>
<p>Finally , how can we withdraw the space??? It is easily we just run “ alter table db engine=innodb;”;</p>
<pre class="brush: sql; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">root@snsfa_02 05:13:10&amp;gt;alter table sns_universal_relations_0064 engine=innodb;
Query OK, 0 rows affected (0.92 sec)
Records: 0  Duplicates: 0  Warnings: 0 

root@snsfa_02 05:13:17&amp;gt;exit
Bye 

[MM-Writable@my130.cm4 /u01/mysql/data/snsfa_02]
$du -sh * | grep sns_universal_relations_0064
12K     sns_universal_relations_0064.frm
132K    sns_universal_relations_0064.ibd</pre>
<p>&#160;</p>
<p>&#160;</p>
<p>InnoDB Plugin-in</p>
<pre class="brush: sql; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">root@(none) 04:55:17&amp;gt; SHOW PLUGINS; 

| InnoDB                         | ACTIVE | STORAGE ENGINE     | NULL             | GPL     |
| INNODB_RSEG                    | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TRX                     | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCKS                   | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCK_WAITS              | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP                     | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP_RESET               | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM                  | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM_RESET            | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLES              | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLESTATS          | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_INDEXES             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_COLUMNS             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FIELDS              | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN_COLS        | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_STATS               | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TABLE_STATS             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_INDEX_STATS             | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES       | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_INDEX | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_BLOB  | ACTIVE | INFORMATION SCHEMA | NULL             | GPL     |
| XTRADB_ADMIN_COMMAND           | ACTIVE | INFORMATION SCHEMA | NULL             | GPL   </pre>
<p>When you are using InnoDB Plugin, it is actually <strong>Effective </strong>for your work.</p>
<p>When you&#160; truncate table,&#160; InnoDB Plugin would help you immediately empty the space.!</p>
<p>&#160;</p>
<p>Reference <a href="http://dev.mysql.com/doc/refman/5.1/en/replacing-builtin-innodb.html">http://dev.mysql.com/doc/refman/5.1/en/replacing-builtin-innodb.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/innodbtruncate-table-difference-between-innodb-build-in-and-innodb-plugin-in/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell脚本批量操作多个表</title>
		<link>http://dbahacker.com/mysql/shell%e8%84%9a%e6%9c%ac%e6%89%b9%e9%87%8f%e6%93%8d%e4%bd%9c%e5%a4%9a%e4%b8%aa%e8%a1%a8</link>
		<comments>http://dbahacker.com/mysql/shell%e8%84%9a%e6%9c%ac%e6%89%b9%e9%87%8f%e6%93%8d%e4%bd%9c%e5%a4%9a%e4%b8%aa%e8%a1%a8#comments</comments>
		<pubDate>Mon, 14 May 2012 14:02:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=224</guid>
		<description><![CDATA[分布式情况下很多分表，比如user_0000到 user_0511 。需要一个简便的批量操作方法。 例如 truncate table . alter table engine=innodb; drop tale等 &#160; 脚本非常简单 &#160; list=`echo &#34;show tables like &#8216;%user%&#8217; &#34; &#124; mysql -uroot test -N ` for i in&#160; $list;do echo &#34;alter table test.$i engine=innodb;&#34; &#124; mysql -uroot test done]]></description>
			<content:encoded><![CDATA[<p>分布式情况下很多分表，比如user_0000到 user_0511 。需要一个简便的批量操作方法。</p>
<p>例如 truncate table . alter table engine=innodb; drop tale等</p>
<p>&#160;</p>
<p>脚本非常简单</p>
<p>&#160;</p>
<p>list=`echo &quot;show tables like &#8216;%user%&#8217; &quot; | mysql -uroot test -N `    <br />for i in&#160; $list;do     <br />echo &quot;alter table test.$i engine=innodb;&quot; | mysql -uroot test     <br />done</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/shell%e8%84%9a%e6%9c%ac%e6%89%b9%e9%87%8f%e6%93%8d%e4%bd%9c%e5%a4%9a%e4%b8%aa%e8%a1%a8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>遭遇MySQL server has gone away</title>
		<link>http://dbahacker.com/mysql/%e9%81%ad%e9%81%87mysql-server-has-gone-away</link>
		<comments>http://dbahacker.com/mysql/%e9%81%ad%e9%81%87mysql-server-has-gone-away#comments</comments>
		<pubDate>Wed, 08 Feb 2012 01:40:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=221</guid>
		<description><![CDATA[一个开发MM的项目(PHP+MySQL)的PHP项目今天出现了MySQL server has gone away的错误，MySQL服务器端表示毫无压力。 而通过mysql客户端的连接方式mysql -hxx -uxx -pxx databasename -e xxx则毫无问题 而App服务器的netstat -a &#124; grep 3306&#160; &#124; grep TIME_WAIT个数非常小，只有2个。 MySQL在连接超时这块的参数如下 root@(none) 09:24:51&#62;show variables like '%out%'; +------------------------------+----------+ &#124; Variable_name &#124; Value &#124; +------------------------------+----------+ &#124; connect_timeout &#124; 10 &#124; &#124; delayed_insert_timeout &#124; 300 &#124; &#124; handlersocket_timeout &#124; 300 &#124; &#124; handlersocket_wrlock_timeout &#124; 12 &#124; &#124; innodb_lock_wait_timeout [...]]]></description>
			<content:encoded><![CDATA[<p>一个开发MM的项目(PHP+MySQL)的PHP项目今天出现了MySQL server has gone away的错误，MySQL服务器端表示毫无压力。</p>
<p>而通过mysql客户端的连接方式mysql -hxx -uxx -pxx databasename -e xxx则毫无问题</p>
<p>而App服务器的netstat -a | grep 3306&#160; | grep TIME_WAIT个数非常小，只有2个。</p>
<p>MySQL在连接超时这块的参数如下</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">root@(none) 09:24:51&gt;show variables like '%out%';
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------------------------------+----------+
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| Variable_name                | Value    |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------------------------------+----------+
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| connect_timeout              | 10       |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| delayed_insert_timeout       | 300      |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| handlersocket_timeout        | 300      |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| handlersocket_wrlock_timeout | 12       |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| innodb_lock_wait_timeout     | 100      |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| innodb_rollback_on_timeout   | OFF      |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| interactive_timeout          | 28800    |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| lock_wait_timeout            | 31536000 |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| log_output                   | FILE     |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| net_read_timeout             | 30       |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| net_write_timeout            | 60       |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| slave_net_timeout            | 3600     |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| wait_timeout                 | 28800    |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------------------------------+----------+</pre>
</pre>
<p>最终MM把PHP连接MySQL的连接方式从长连接改成了短连接，就再没出现了。</p>
<p>后来查了下资料，总结如下</p>
<p>1.MySQL服务器的<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_wait_timeout"><code>wait_timeout</code></a>参数为默认的28800秒，即8小时。该参数的意思是MySQL等待睡眠的连接的持续时间，如果超过8小时不活动，MySQL就会关闭这个连接。这个参数可以动态修改，但这个参数是session级别的，需要应用重新建立连接获取这个变量值才会生效。</p>
<p>2.PHP的默认php.ini里面，default_socket_timeout参数是默认60s.default_socket_timeout参数的意思是socket超时为60s。 <a href="http://cn.php.net/manual/en/filesystem.configuration.php#ini.default-socket-timeout" target="_blank">官方解释</a></p>
<p>3.在MySQL的官方文档里面，有<a href="http://dev.mysql.com/doc/refman/5.1/en/gone-away.html" target="_blank">专门的章节</a>介绍MySQL Server has gone away。但并没有提及到客户端本身也会有超时机制，以前曾经试过把<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_wait_timeout"><code>wait_timeout</code></a>设置为1年，但App还是继续出现MySQL server has gone away的错误。</p>
<p>4.在PHP程序里面，如果php.ini修改起来不方便，可以以下代码来尝试解决。</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">ini_set('mysql.connect_timeout', 300);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">ini_set('default_socket_timeout', 300);</pre>
</pre>
<p>在ini_set后，可以用ini_get来验证参数设置适合符合预期。</p>
<p>&#160;</p>
<p>参考资料 </p>
<p>1. <a href="http://stackoverflow.com/questions/1644432/mysql-server-has-gone-away-in-exactly-60-seconds" target="_blank">MySQL server has gone away &#8211; in exactly 60 seconds</a></p>
<p>2.<a href="http://dev.mysql.com/doc/refman/5.1/en/gone-away.html" target="_blank">MySQL server has gone away</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/%e9%81%ad%e9%81%87mysql-server-has-gone-away/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL group by with rollup的用法</title>
		<link>http://dbahacker.com/mysql/mysql-group-by-with-rollup%e7%9a%84%e7%94%a8%e6%b3%95</link>
		<comments>http://dbahacker.com/mysql/mysql-group-by-with-rollup%e7%9a%84%e7%94%a8%e6%b3%95#comments</comments>
		<pubDate>Wed, 01 Feb 2012 07:48:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=219</guid>
		<description><![CDATA[有一位同学通过askdba来询问with rollup的用法 (2012-02-01 15:08:22): mysql中有这种用法select ... from table_name group by a with rollup &#34;with rollup&#34;是什么意思呢？ GROUP BY Modifiers&#160; 官方手册里面对这个rollup有一个专门的页面介绍 地址在这里，说得非常详细，我这里做一个简单的例子重现 建一个简单的表并插入几条简单的数据 CREATE TABLE `t` ( `id` int(11) DEFAULT NULL, `id2` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=gbk insert into t valeu(11,11),(12,12),(13,13); 先来做一个查询 root@test 03:44:32&#62;select id,sum(id2),avg(id2) from t group by id with rollup; +------+----------+----------+ &#124; id [...]]]></description>
			<content:encoded><![CDATA[<p>有一位同学通过askdba来询问with rollup的用法</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">(2012-02-01 15:08:22):
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"> mysql中有这种用法select ... from table_name  group by a with rollup
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">&quot;<span style="color: #8b0000">with rollup</span>&quot;是什么意思呢？
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
</pre>
<p>GROUP BY Modifiers&#160; 官方手册里面对这个rollup有一个专门的页面介绍 <a href="http://dev.mysql.com/doc/refman/5.5/en/group-by-modifiers.html" target="_blank">地址在这里</a>，说得非常详细，我这里做一个简单的例子重现</p>
<p>建一个简单的表并插入几条简单的数据</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">CREATE TABLE `t` (
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">  `id` <span style="color: #0000ff">int</span>(11) DEFAULT NULL,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">  `id2` <span style="color: #0000ff">int</span>(11) DEFAULT NULL
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">) ENGINE=InnoDB DEFAULT CHARSET=gbk
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">insert into t valeu(11,11),(12,12),(13,13);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
</pre>
<p>先来做一个查询</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">root@test 03:44:32&gt;select id,sum(id2),avg(id2) from t group by id with rollup;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------+----------+----------+
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| id   | sum(id2) | avg(id2) |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------+----------+----------+
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">|   11 |       11 |  11.0000 |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">|   12 |       12 |  12.0000 |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">|   13 |       13 |  13.0000 |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| NULL |       36 |  12.0000 |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------+----------+----------+
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">4 rows in set (0.00 sec)</pre>
</pre>
<p>我们可以看到，对于group by的列，with rollup将不会做任何的操作，而是返回一个NULL，而没有group by的列，则根据前面的avg函数和sum函数做了处理。 </p>
<p>再来看另外一个语句，只对一个列做avg</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">root@test 03:44:36&gt;select id,avg(id2) from t group by id with rollup;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------+----------+
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| id   | avg(id2) |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------+----------+
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">|   11 |  11.0000 |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">|   12 |  12.0000 |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">|   13 |  13.0000 |
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">| NULL |  12.0000 |
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">+------+----------+
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">4 rows in set (0.00 sec)</pre>
</pre>
<p>以前从没留意到有这种用法，这次长见识了。 </p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/mysql-group-by-with-rollup%e7%9a%84%e7%94%a8%e6%b3%95/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>redhat5 和redhat6 root用户不同的ulimits</title>
		<link>http://dbahacker.com/linux/redhat5-%e5%92%8credhat6-root%e7%94%a8%e6%88%b7%e4%b8%8d%e5%90%8c%e7%9a%84ulimits</link>
		<comments>http://dbahacker.com/linux/redhat5-%e5%92%8credhat6-root%e7%94%a8%e6%88%b7%e4%b8%8d%e5%90%8c%e7%9a%84ulimits#comments</comments>
		<pubDate>Tue, 31 Jan 2012 09:27:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[redhat6]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=214</guid>
		<description><![CDATA[以前一直都是用redhat5，redhat6也处于测试阶段，当然也遇到了很多奇奇怪怪的问题，比如之前写的一篇博客,当时候是用root启动了mysqld_unsafe，在mysql的QPS到1W以上后，会出现ERROR 1135 (HY000): Can’t create a new thread (errno 11); 当时候的解决办法是用mysql用户来启动就解决了问题。但因为在系统重启后，如果用sudo&#160; -u mysql来启动的话，脚本会被卡主。 这个问题今天得到了一个稍微深入一点的结论。 首先我们看看这个错误 ERROR 1135 (HY000): Can’t create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug google类似Can’t create a new thread的错误后，得到的结论是文件描述符不够用，检查了vim /etc/security/limits.conf&#160;&#160; 的设置，是正常的 vim /etc/security/limits.conf 得到的结果是 root soft [...]]]></description>
			<content:encoded><![CDATA[<p><font face="新宋体">以前一直都是用redhat5，redhat6也处于测试阶段，当然也遇到了很多奇奇怪怪的问题，比如之前写的一篇</font><a href="http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11" target="_blank"><font face="新宋体">博客</font></a><font face="新宋体">,当时候是用root启动了mysqld_unsafe，在mysql的QPS到1W以上后，会出现ERROR 1135 (HY000): Can’t create a new thread (errno 11); 当时候的解决办法是用mysql用户来启动就解决了问题。但因为在系统重启后，如果用sudo&#160; -u mysql来启动的话，脚本会被卡主。</font></p>
<p><font face="新宋体">这个问题今天得到了一个稍微深入一点的结论。</font></p>
<p><font face="新宋体">首先我们看看这个错误</font></p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">ERROR 1135 (HY000): Can’t create a new thread (errno 11);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">if</span> you are not out of available memory,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">you can consult the manual <span style="color: #0000ff">for</span> a possible OS-dependent bug</pre>
</pre>
<p>google类似Can’t create a new thread的错误后，得到的结论是文件描述符不够用，检查了vim /etc/security/limits.conf&#160;&#160; 的设置，是正常的</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">vim /etc/security/limits.conf
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">得到的结果是
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">root    soft    nofile  65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">root    hard    nofile  65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">admin   soft    nofile  65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">admin   hard    nofile  65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># End of file
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   soft    nproc   65536
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   hard    nproc   65536
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   soft    nofile  65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   hard    nofile  65535</pre>
</pre>
<div class="csharpcode">但观察了sudo -u root bash -c &quot; ulimit -a &quot; 后，得到 max user processes&#160;&#160; (-u) 1024</div>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">core file size          (blocks, -c) 0
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">data seg size           (kbytes, -d) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">scheduling priority             (-e) 0
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">file size               (blocks, -f) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">pending signals                 (-i) 385957
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">max locked memory       (kbytes, -l) 64
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">max memory size         (kbytes, -m) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">open</span> files                      (-n) 65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">pipe size            (512 bytes, -p) 8
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">POSIX message queues     (bytes, -q) 819200
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">real-<span style="color: #0000ff">time</span> priority              (-r) 0
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">stack size              (kbytes, -s) 10240
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">cpu <span style="color: #0000ff">time</span>               (seconds, -t) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">max user processes              (-u) 1024
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">virtual memory          (kbytes, -v) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">file locks                      (-x) unlimited</pre>
</pre>
<div class="csharpcode">max user processes&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (-u) 1024 和 sudo -u root bash -c &quot; ulimit -u &quot;&#160; 一样，都是得到1024的结果</div>
<pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">sudo -u root bash -c &quot;<span style="color: #8b0000"> ulimit -u </span>&quot;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">1024</pre>
</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>而在redhat5里面，只要在/etc/security/limits.conf&#160; 设置了root&#160;&#160;&#160; soft&#160;&#160;&#160; nofile&#160; 65535 和root&#160;&#160;&#160; hard&#160;&#160;&#160; nofile&#160; 65535，对应的uilmit&#160; -u 就会是65535. </p>
<p>和@维西v @tb天羽 搞了几个小时，依然没法成功修改root用户的 max user processes到65535 。后来发现了<a href="http://dlutzy.wordpress.com/2011/05/19/know-your-limits-ulimits/" target="_blank">一篇文章</a> Know your limits (ulimits)&#160; ，提及到redhat6新增了/etc/security/limits.d/90-nproc.conf，里面的内容是</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># Default limit <span style="color: #0000ff">for</span> number of user's processes to prevent
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># accidental fork bombs.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># See rhbz #432903 <span style="color: #0000ff">for</span> reasoning.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">*          soft    nproc     1024</pre>
</pre>
<p><strong><font size="4">redhat6下面，root用户使用ulimit -u没法修改</font></strong></p>
<p>* soft nproc 1024的意思是任何用户的最大max user processes为1024个，其他用户可以通过ulimit -u来修改 ，但root用户则修改不成功，我们这里看一个例子</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ cat /etc/security/limits.d/90-nproc.conf
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># Default limit <span style="color: #0000ff">for</span> number of user's processes to prevent
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># accidental fork bombs.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># See rhbz #432903 <span style="color: #0000ff">for</span> reasoning.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">*          soft    nproc     1024
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ ulimit -u
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">1024
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ ulimit -u 65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ ulimit -u
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u 65535</span>&quot;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u </span>&quot;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">1024
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
</pre>
<p>很明显，在redhat6的/etc/security/limits.d/90-nproc.conf限制下，个人用户可以修改ulimit-u,但root用户没法修改。 <strong>解下来，我们把etc/security/limits.d/90-nproc.conf改掉，会看到root的ulimit -u 可以修改成功</strong>。 </p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u 65535</span>&quot;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u </span>&quot;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ cat /etc/security/limits.d/90-nproc.conf
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># Default limit <span style="color: #0000ff">for</span> number of user's processes to prevent
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># accidental fork bombs.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># See rhbz #432903 <span style="color: #0000ff">for</span> reasoning.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">*          soft    nproc     65535</pre>
</pre>
<p><strong><font size="4">结果</font></strong></p>
<p><strong><font size="4"></font></strong>在成功修改了root用户的max user processes后，继续使用root用户启动mysqld_safe脚本，稳定运行了一个下午，一切正常。 </p>
<p><strong><font size="4">思考</font></strong></p>
<p>为什么redhat6要做新增一个文件的限制，而不是继续沿用redhat5的方式来管理？ 在微博上面发了一条简单的描述，引起很多人的讨论。 </p>
<p><a href="http://weibo.com/1642466057/y3jM4cz3q">http://weibo.com/1642466057/y3jM4cz3q</a></p>
</p>
<p><font face="新宋体"></font></p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/redhat5-%e5%92%8credhat6-root%e7%94%a8%e6%88%b7%e4%b8%8d%e5%90%8c%e7%9a%84ulimits/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>遭遇Linux进程状态D</title>
		<link>http://dbahacker.com/linux/%e9%81%ad%e9%81%87linux%e8%bf%9b%e7%a8%8b%e7%8a%b6%e6%80%81d</link>
		<comments>http://dbahacker.com/linux/%e9%81%ad%e9%81%87linux%e8%bf%9b%e7%a8%8b%e7%8a%b6%e6%80%81d#comments</comments>
		<pubDate>Thu, 19 Jan 2012 14:37:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=211</guid>
		<description><![CDATA[在一台flashcache的机器上面跑stap脚本 global some_count probe process(@1).function(&#34;*&#34;) { &#160; some_count[tid()] = backtrace() } function print_top() { &#160; foreach (tid+ in some_count) &#160; { &#160;&#160;&#160; print_stack(some_count[tid]) &#160; } } probe timer.s(5) { &#160; print_top() &#160; printf(&#34;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\n&#34;) } 跑了这个脚本，跑了一会就ctrl+c abort掉，但后台还是有一个D进程的程序，用了好几次kill -9也杀不掉 1 15466 15252 14863 ?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -1 D&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0&#160;&#160; 0:00 /usr/libexec/systemtap/stapio -u /tmp/stapzHoiGc/stap_b2dc831605d82ca90db5b550e7dfd16a_24607.ko 在Linux里面，进程状态分为task_running,task_interruptiable,task_uninterruptiable，_task_traced _task_stopped 之前一直对task_uninterruptiable不是很理解，这次亲身经历后，对它的认识更加深入。 进程状态为D的进程，一直滞留在CPU run_queue里面，搞得我的其他进程都不能正常运行，尝试了kill –9 [...]]]></description>
			<content:encoded><![CDATA[<p>在一台flashcache的机器上面跑stap脚本</p>
<blockquote><p>global some_count     <br />probe process(@1).function(&quot;*&quot;)      <br />{      <br />&#160; some_count[tid()] = backtrace()      <br />} </p>
<p>function print_top()     <br />{      <br />&#160; foreach (tid+ in some_count)      <br />&#160; {      <br />&#160;&#160;&#160; print_stack(some_count[tid])      <br />&#160; }      <br />} </p>
<p>probe timer.s(5)     <br />{      <br />&#160; print_top()      <br />&#160; printf(&quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\n&quot;)      <br />}</p>
</blockquote>
<p>跑了这个脚本，跑了一会就ctrl+c abort掉，但后台还是有一个D进程的程序，用了好几次kill -9也杀不掉</p>
<blockquote><p>1 15466 15252 14863 ?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -1 D&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0&#160;&#160; 0:00 /usr/libexec/systemtap/stapio -u /tmp/stapzHoiGc/stap_b2dc831605d82ca90db5b550e7dfd16a_24607.ko</p>
</blockquote>
<p>在Linux里面，进程状态分为task_running,task_interruptiable,task_uninterruptiable，_task_traced _task_stopped</p>
<p>之前一直对task_uninterruptiable不是很理解，这次亲身经历后，对它的认识更加深入。</p>
<p>进程状态为D的进程，一直滞留在CPU run_queue里面，搞得我的其他进程都不能正常运行，尝试了kill –9 ，没办法杀掉。最后只能reboot解决</p>
<p>之所以命名为D，往往是因为I/O资源得不到满足而引发等待。</p>
<p>我们的备库依赖nas服务器来作为备份盘，今年遇到过好几次因为nas的问题，导致mysql的监控一直告警(监控程序需要连接到MySQL,但由于备份脚本因为在写nas的时候，nas在中途卸载掉了，导致脚本一直在等待nas就绪,必须得重新挂载nas才能解决)</p>
<p>&#160;</p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/01/image4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb4.png" width="559" height="421" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/%e9%81%ad%e9%81%87linux%e8%bf%9b%e7%a8%8b%e7%8a%b6%e6%80%81d/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CPU软中断实践一</title>
		<link>http://dbahacker.com/linux/cpu%e8%bd%af%e4%b8%ad%e6%96%ad%e5%ae%9e%e8%b7%b5%e4%b8%80</link>
		<comments>http://dbahacker.com/linux/cpu%e8%bd%af%e4%b8%ad%e6%96%ad%e5%ae%9e%e8%b7%b5%e4%b8%80#comments</comments>
		<pubDate>Tue, 17 Jan 2012 18:03:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=206</guid>
		<description><![CDATA[最近在对一个MySQL项目进行性能测试 QPS在1.1W到1.5W之间波动，但通过tcprstat观察到，响应时间不是非常稳定，会从0.3ms波动到1.9ms 响应时间监控，avg代表的是平均响应时间，单位为微秒，这里可以看到，平均响应时间为0.3ms 到1.7ms之间波动 @淘宝褚霸 在帮忙分析的时候，给了三点建议 1.CPU 2.IO 3.内存 这里先从CPU使用优化来总结一下 1.首先定位系统的CPU占用是否正常，可以使用 命令 mpstat –P ALL&#160; 1 我们可以看到第四颗CPU的idle百分比明显比其他CPU要低好多。那这颗CPU到底在忙什么事情？&#160;&#160;&#160; perf top 工具可以帮我们查看，这颗CPU上面跑的进程的百分比 2. sudo perf top &#8211;cpu=4 输出的结果和oprofile相似，但perf top可以实时来做cpu采样，这点比oprofile要好使得多。 另外一个工具是 taskset ,例如 taskset -p 03 700&#160; 的意思是把pid为700的进程绑定到第四颗CPU上面]]></description>
			<content:encoded><![CDATA[<p>最近在对一个MySQL项目进行性能测试 QPS在1.1W到1.5W之间波动，但通过tcprstat观察到，响应时间不是非常稳定，会从0.3ms波动到1.9ms</p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/01/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb.png" width="550" height="262" /></a> </p>
<p><font face="宋体">响应时间监控，avg代表的是平均响应时间，单位为微秒，这里可以看到，平均响应时间为0.3ms 到1.7ms之间波动</font></p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/01/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb1.png" width="540" height="154" /></a> </p>
<p><font face="宋体"><a href="http://weibo.com/tchuba" target="_blank">@淘宝褚霸</a> 在帮忙分析的时候，给了三点建议 1.CPU 2.IO 3.内存 这里先从CPU使用优化来总结一下</font></p>
<p><font face="宋体">1.首先定位系统的CPU占用是否正常，可以使用 命令 mpstat –P ALL&#160; 1</font><a href="http://dbahacker.com/wp-content/uploads/2012/01/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb2.png" width="548" height="211" /></a> </p>
<p><font face="宋体">我们可以看到第四颗CPU的idle百分比明显比其他CPU要低好多。那这颗CPU到底在忙什么事情？&#160;&#160;&#160; perf top 工具可以帮我们查看，这颗CPU上面跑的进程的百分比</font></p>
<p><font face="宋体">2. <strong>sudo perf top &#8211;cpu=4</strong> </font><a href="http://dbahacker.com/wp-content/uploads/2012/01/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb3.png" width="540" height="344" /></a> </p>
<p>输出的结果和oprofile相似，但perf top可以实时来做cpu采样，这点比oprofile要好使得多。 </p>
</p>
<p>另外一个工具是 taskset ,例如 taskset -p 03 700&#160; 的意思是把pid为700的进程绑定到第四颗CPU上面</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/cpu%e8%bd%af%e4%b8%ad%e6%96%ad%e5%ae%9e%e8%b7%b5%e4%b8%80/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ERROR 1135 (HY000): Can&#8217;t create a new thread (errno 11)</title>
		<link>http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11</link>
		<comments>http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11#comments</comments>
		<pubDate>Mon, 09 Jan 2012 13:33:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=171</guid>
		<description><![CDATA[在一台MySQL测试服务器上面，今天遇到了 ERROR 1135 (HY000): Can&#8217;t create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug 首先使用perror工具看一下 错误代码11代表的意思 perror 11 OS error code 11: Resource temporarily unavailable 资源暂时不可用 google搜索了一下，很多文章说和当前用户的文件描述符ulimit -n有关系 ulimit -n 65535 当时候mysql的服务器load 为0，自然不可能是文件描述符不够导致的问题 第二个检查操作 cat /etc/security/limits.conf 得到的结果是 root soft nofile 65535 root hard nofile 65535 admin soft nofile 65535 admin hard nofile 65535 # End of file mysql soft nproc 65536 mysql hard nproc 65536 mysql soft [...]]]></description>
			<content:encoded><![CDATA[<p>在一台MySQL测试服务器上面，今天遇到了</p>
<p><span style="color: #000000; font-family: 宋体;">ERROR 1135 (HY000): Can&#8217;t create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug</span></p>
<p>首先使用perror工具看一下 错误代码11代表的意思</p>
<p>perror 11<br />
OS error code  11:  Resource temporarily unavailable<br />
资源暂时不可用<br />
google搜索了一下，很多文章说和当前用户的文件描述符ulimit -n有关系<br />
ulimit -n<br />
65535<br />
当时候mysql的服务器load 为0，自然不可能是文件描述符不够导致的问题<br />
<strong>第二个检查操作</strong> cat /etc/security/limits.conf<br />
得到的结果是<br />
root    soft    nofile  65535<br />
root    hard    nofile  65535<br />
admin   soft    nofile  65535<br />
admin   hard    nofile  65535<br />
# End of file<br />
mysql   soft    nproc   65536<br />
mysql   hard    nproc   65536<br />
mysql   soft    nofile  65535<br />
<strong>第三个检查操作 查看mysql的错误日志</strong><br />
有一个很奇怪的现象，我的mysql是一直跑着的，但错误日志只有前两天的</p>
<p>这个时候，在ps aux | grep mysql的输出中发现 -log-error=/var/log/mysqld.log ，错误日志输出到/var目录下面是不正常的<br />
<span style="color: #000000; font-family: 宋体;">mysql     2086 35.1 37.1 51184004 18388068 ?   Sl   20:25   9:01 </span><br />
<span style="color: #000000; font-family: 宋体;">/u01/mysql/bin/mysqld &#8211;basedir=/u01/mysql &#8211;datadir=/u01/mysql/data &#8211;plugin-dir=/u01/mysql/lib/plugin</span><br />
<span style="color: #000000; font-family: 宋体;"> &#8211;user=mysql &#8211;log-error=/var/log/mysqld.log &#8211;open-files-limit=65535 &#8211;pid-file=/u01/mysql/run/mysqld.pid</span><br />
<span style="color: #000000; font-family: 宋体;"> &#8211;socket=/u01/mysql/run/mysql.sock &#8211;port=3306</span></p>
<p>直觉告诉我mysql用了/etc/my.cnf的内容<br />
/etc/my.cnf的内容<br />
[mysqld]<br />
datadir=/var/lib/mysql<br />
socket=/var/lib/mysql/mysql.sock<br />
user=mysql<br />
# Disabling symbolic-links is recommended to prevent assorted security risks<br />
symbolic-links=0</p>
<p>[mysqld_safe]<br />
log-error=/var/log/mysqld.log<br />
pid-file=/var/run/mysqld/mysqld.pid</p>
<p>最终把mysqld_safe干掉后，用mysqld_safe &#8211;defaults-file=xx.cnf 重新指定my.cnf的位置，mysql就正常跑了<br />
最终原因，<a href="http://weibo.com/rezic7">@维西v</a> 启动mysql的时候没有指定my.cnf的位置，所以导致mysqld_safe使用了/etc/my.cnf这个默认文件<br />
但依然有问题不是很理解<br />
1.为什么读了/etc/my.cnf的时候，mysqld还会继续使用my.cnf配置文件里面的/u01/mysql/data<br />
2.为什么还会继续使用plugin-dir=/u01/mysql/lib/plugin</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>编译Percona MySQL 5.5 +Handler Socket</title>
		<link>http://dbahacker.com/linux/mysql5-5-hs</link>
		<comments>http://dbahacker.com/linux/mysql5-5-hs#comments</comments>
		<pubDate>Wed, 02 Nov 2011 14:32:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=161</guid>
		<description><![CDATA[安装准备 Cmake wget http://service-spi.web.cern.ch/service-spi/external/tarFiles/cmake-2.6.4.tar.gz Percona-Server-5.5.16-rel22.0  get http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.16-22.0/source/Percona-Server-5.5.16-rel22.0.tar.gz $tar zxf cmake-2.6.4.tar.gz $cd cmake-2.6.4 $./bootstrap $make $sudo make install tar zxvf  Percona-Server-5.5.15-rel22.0.tar.gz cd  Percona-Server-5.5.15-rel22.0 执行 CFLAGS=”-O3&#8243; CXX=gcc CXXFLAGS=”-O3 -felide-constructors -fno-exceptions -fno-rtti” &#160; cmake . \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DSYSCONFDIR:PATH=/u01/mysql \ -DCMAKE_INSTALL_PREFIX:PATH=/u01/mysql \ -DENABLED_PROFILING:BOOL=ON \ -DENABLE_DEBUG_SYNC:BOOL=OFF \ -DMYSQL_DATADIR:PATH=/u01/mysql/data \ -DMYSQL_MAINTAINER_MODE:BOOL=OFF \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312 \ -DWITH_BIG_TABLES:BOOL=ON \ -DWITH_FAST_MUTEXES:BOOL=ON \ -DENABLE-PROFILING:BOOL=ON \ -DWITH_SSL:STRING=bundled \ -DWITH_UNIT_TESTS:BOOL=OFF \ -DWITH_ZLIB:STRING=bundled \ -DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON \ -DWITH_SERVER_SUFFIX=hxsw \ -DWITH_PLUGINS=heap,csv,partition,innodb_plugin,myisam [...]]]></description>
			<content:encoded><![CDATA[<p>安装准备 Cmake wget http://service-spi.web.cern.ch/service-spi/external/tarFiles/cmake-2.6.4.tar.gz</p>
<p>Percona-Server-5.5.16-rel22.0  get http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.16-22.0/source/Percona-Server-5.5.16-rel22.0.tar.gz</p>
<div id="Msg_{738F92AD-B4C8-4D37-976E-797F91F847B1}"><span style="color: #000000; font-family: 宋体;">$tar zxf cmake-2.6.4.tar.gz<br />
$cd cmake-2.6.4<br />
$./bootstrap<br />
$make<br />
$sudo make install</span></div>
<p>tar zxvf  Percona-Server-5.5.15-rel22.0.tar.gz</p>
<p>cd  Percona-Server-5.5.15-rel22.0</p>
<p>执行 CFLAGS=”-O3&#8243; CXX=gcc CXXFLAGS=”-O3 -felide-constructors -fno-exceptions -fno-rtti”</p>
<p>&nbsp;</p>
<pre>cmake . \
  -DCMAKE_BUILD_TYPE:STRING=Release             \
  -DSYSCONFDIR:PATH=/u01/mysql            \
  -DCMAKE_INSTALL_PREFIX:PATH=/u01/mysql  \
  -DENABLED_PROFILING:BOOL=ON                   \
  -DENABLE_DEBUG_SYNC:BOOL=OFF                  \
  -DMYSQL_DATADIR:PATH=/u01/mysql/data    \
  -DMYSQL_MAINTAINER_MODE:BOOL=OFF              \
  -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312  \
  -DWITH_BIG_TABLES:BOOL=ON \
  -DWITH_FAST_MUTEXES:BOOL=ON \
  -DENABLE-PROFILING:BOOL=ON \
  -DWITH_SSL:STRING=bundled                     \
  -DWITH_UNIT_TESTS:BOOL=OFF                    \
  -DWITH_ZLIB:STRING=bundled                    \
  -DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON       \
  -DWITH_SERVER_SUFFIX=hxsw                        \
  -DWITH_PLUGINS=heap,csv,partition,innodb_plugin,myisam \
  -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_EXTRA_CHARSETS=ALL \
  -DENABLED_ASSEMBLER:BOOL=ON                   \
  -DENABLED_LOCAL_INFILE:BOOL=ON                \
  -DENABLED_THREAD_SAFE_CLIENT:BOOL=ON          \
  -DENABLED_EMBEDDED_SERVER:BOOL=OFF             \
  -DWITH_CLIENT_LDFLAGS:STRING=all-static                 \
  -DINSTALL_LAYOUT:STRING=STANDALONE            \
  -DCOMMUNITY_BUILD:BOOL=ON;</pre>
<pre> make -j `cat /proc/cpuinfo  | grep processor | wc -l`</pre>
<pre>make install</pre>
<p>执行/u01/mysql/scripts/mysql_install_db &#8211;basedir=/u01/mysql/</p>
<p>(安装mysql,test数据库，初始化权限)</p>
<p>启动MySQL /u01/mysql/bin/mysqld_safe &#8211;defaults-file=my.cnf &amp;</p>
<p>(my.cnf 请参考/u01/pmysql/support-files 下面的 my-innodb-heavy-4G.cnf文件 ）</p>
<p>启动MySQL后，登录后</p>
<pre>Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.16-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)</pre>
<p>恭喜你，已经安装成功了！</p>
<p><strong>编译Handler Socket</strong></p>
<p>cd Percona-Server-5.5.16-rel22.0/storage/HandlerSocket-Plugin-for-MySQL</p>
<p>./configure  &#8211;with-mysql-source=/home/xxx/Percona-Server-5.5.15-rel21.0 \</p>
<p>&#8211;with-mysql-bindir=/u01/mysql/bin/ &#8211;with-mysql-plugindir=/u01/mysql/lib/plugin</p>
<p>&nbsp;</p>
<p>make -j `cat /proc/cpuinfo  | grep processor | wc -l`</p>
<p>make install</p>
<p>登录到MySQL</p>
<p>mysql&gt;  INSTALL PLUGIN handlersocket SONAME &#8216;handlersocket.so&#8217;;</p>
<p><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">mysql&gt; show plugins;</span></p>
<pre>+--------------------------------+----------+--------------------+------------------+---------+
| Name                           | Status   | Type               | Library          | License |
+--------------------------------+----------+--------------------+------------------+---------+
| binlog                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| mysql_native_password          | ACTIVE   | AUTHENTICATION     | NULL             | GPL     |
| mysql_old_password             | ACTIVE   | AUTHENTICATION     | NULL             | GPL     |
| MRG_MYISAM                     | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| MEMORY                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| MyISAM                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| CSV                            | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| BLACKHOLE                      | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| InnoDB                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| INNODB_RSEG                    | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TRX                     | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCKS                   | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCK_WAITS              | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP                     | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP_RESET               | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM                  | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM_RESET            | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLES              | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLESTATS          | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_INDEXES             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_COLUMNS             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FIELDS              | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN_COLS        | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_STATS               | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TABLE_STATS             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_INDEX_STATS             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES       | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_INDEX | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_BLOB  | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| XTRADB_ADMIN_COMMAND           | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| FEDERATED                      | DISABLED | STORAGE ENGINE     | NULL             | GPL     |
| ARCHIVE                        | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| PERFORMANCE_SCHEMA             | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| partition                      | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| handlersocket                  | ACTIVE   | DAEMON             | handlersocket.so | BSD     |
+--------------------------------+----------+--------------------+------------------+---------+
36 rows in set (0.00 sec)</pre>
<pre></pre>
<p>参考资料 Cmake使用   <a href="http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide">http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/mysql5-5-hs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

