<?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实践积累 &#187; MySQL</title>
	<atom:link href="http://dbahacker.com/archive/mysql/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>MySQL 5.0 5.1 下InnoDB的预热方法</title>
		<link>http://dbahacker.com/mysql/mysql-5-0-5-1-%e4%b8%8binnodb%e7%9a%84%e9%a2%84%e7%83%ad%e6%96%b9%e6%b3%95</link>
		<comments>http://dbahacker.com/mysql/mysql-5-0-5-1-%e4%b8%8binnodb%e7%9a%84%e9%a2%84%e7%83%ad%e6%96%b9%e6%b3%95#comments</comments>
		<pubDate>Tue, 05 Oct 2010 07:13:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[MySQL5.0]]></category>
		<category><![CDATA[MySQL5.1]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=150</guid>
		<description><![CDATA[asdfsdfsadf0.00 creates/s, 0.00 writes/s Buffer pool hit rate 757 / 1000 &#8212;&#8212;&#8212;&#8212;&#8211; ROW OPERATIONS &#8212;&#8212;&#8212;&#8212;&#8211; 0 queries inside InnoDB, 0 queries in queue 1 read views open inside InnoDB Main thread process no. 12487, id 1157658976, state: waiting for server activity Number of rows inserted 0, updated 0, deleted 0, read 21 0.00 inserts/s, 0.00 [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">asdfsdfsadf0.00 creates/s, 0.00 writes/s</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">Buffer pool hit rate 757 / 1000</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">ROW OPERATIONS</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">0 queries inside InnoDB, 0 queries in queue</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">1 read views open inside InnoDB</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">Main thread process no. 12487, id 1157658976, state: waiting for server activity</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">Number of rows inserted 0, updated 0, deleted 0, read 21</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.07 reads/s</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">END OF INNODB MONITOR OUTPUT</div>
<div id="_mcePaste" style="position: absolute; overflow-x: hidden; overflow-y: hidden; width: 1px; height: 1px; top: 0px; left: -10000px;">==========================MyS</div>
<p>之前在做一个项目的MySQL数据库极限压测, 有部分场景是涉及到MySQL重启的,而这个项目使用的是InnoDB存储引擎。</p>
<p>重启完毕后,一开始十几分钟的性能是非常差的,原因是因为InnoDB有innodb buffer pool(简称ibf)的概念</p>
<p>和innodb buffer pool相关的参数innodb_buffer_pool_size,size越大,可以放到内存的数据越多,而大多数的项目都会有热点数据的存在,当热点数据经过LRU算法进入到buffer pool之后,读磁盘的次数减少,读的都是内存,速度是最快的</p>
<p>问题来了,数据库一重启,热点数据都被清空,bf里面都是空的.等待app的sql请求过来让bf填满数据是一个方法,但30分钟内很难把热点数据都装载进来.</p>
<p>这个时候,我们可以采取人工预热的办法来让bf满足我们的需求</p>
<p><strong>MySQL 5.0的预热是最简单的</strong></p>
<p>方法1 : 在MySQL重启后 执行 SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES,经过我在一台5.0MySQL的实验 在重启后查看show innodb status\G 和执行完这条语句后 Free buffers的页数会减少.</p>
<p>这个count语句有何作用呢?InnoDB的存储格式和MyISAM不一样, innodb会在mysql启动后的第一次访问表的时候,统计表的索引基数等相关信息,如果表很多的话,这也是一个巨大的开销.所以在正式提供服务之前,就把表打开,放入到bp里面</p>
<p><strong>MySQL 5.1的数据预热</strong></p>
<p>我在一台5.1.48的MySQL进行了重启,测试了同样的SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES 但发现free buffers的页数没有变少，情况和mysqlperformanceblog.com作者所说的一样&#8211;这个方法在5.1之后就无法达到我们的需求了</p>
<p>可以采用另外一种方法:获得数据库里面的库和对应的表，来进行预热，核心代码是这一句</p>
<p>SELECT table_schema, table_name FROM information_schema.tables</p>
<p>可以用perl或者python来获取库和表 然后执行 select * from db.table limit 1 来实现我们的方法</p>
<p>最后提一下,我们可以再my.cnf 加入init-file=/mysql/init.sql ，在每次mysql重启的时候就自动执行这个预热的sql  当然了 sql是要我们自己生成的哦</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/mysql-5-0-5-1-%e4%b8%8binnodb%e7%9a%84%e9%a2%84%e7%83%ad%e6%96%b9%e6%b3%95/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL InnoDB 崩溃恢复过程  前言</title>
		<link>http://dbahacker.com/mysql/mysql-innodb-%e5%b4%a9%e6%ba%83%e6%81%a2%e5%a4%8d%e8%bf%87%e7%a8%8b-%e5%89%8d%e8%a8%80</link>
		<comments>http://dbahacker.com/mysql/mysql-innodb-%e5%b4%a9%e6%ba%83%e6%81%a2%e5%a4%8d%e8%bf%87%e7%a8%8b-%e5%89%8d%e8%a8%80#comments</comments>
		<pubDate>Thu, 09 Sep 2010 01:02:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=134</guid>
		<description><![CDATA[最近一个正在进行的项目，性能测试场景中包含MySQL 为较大压力的应用程序提供服务，Linux服务器CPU占用100% ，OS 不可用，我写了一个吃CPU的shell脚本来不断的跑，结果把服务器跑挂了，手动重启了服务器后，发现MySQL起来的时间需要非常长，为大家所不能接受 MySQL相关信息   5.0.67    InnoDB Buffer Pool Size为36G  ,innodb_flush_log_at_trx_commit = 1，innodb_log_file_size = 900M ，当时候的服务器情况比较糟糕，CPU占用100% ，ssh也登录不进去，维持了一段时间后才进行重启，所以没有收集到最重要的崩溃之前的MySQL内部信息   整个的恢复过程用了6个小时 这个时候，引发了我们的反思: 1. 我们的MySQL压测模型没有针对不同版本的MySQL进行崩溃恢复压测  所以出现这个崩溃恢复的问题，我们只能补回来这个测试，针对不同版本的MySQL(MySQL 5.0.67 和MySQL5.1.xx)，需要进行相同TPS的场景下进行kill -9  pid (mysqld)的测试，掌握一手的崩溃恢复时间，为将来线上出现MySQL崩溃，做最好的准备 2. 我自己对MySQL InnoDB崩溃恢复的过程不是非常了解,导致MySQL崩溃之前没有去采集有参考价值的数值，这点需要加把劲 这一篇是前言，下一篇，我会对MySQL InnoDB的崩溃恢复过程做详细的介绍]]></description>
			<content:encoded><![CDATA[<p>最近一个正在进行的项目，性能测试场景中包含MySQL 为较大压力的应用程序提供服务，Linux服务器CPU占用100% ，OS 不可用，我写了一个吃CPU的shell脚本来不断的跑，结果把服务器跑挂了，手动重启了服务器后，发现MySQL起来的时间需要非常长，为大家所不能接受</p>
<p>MySQL相关信息   5.0.67    InnoDB Buffer Pool Size为36G  ,innodb_flush_log_at_trx_commit = 1，innodb_log_file_size = 900M</p>
<p>，当时候的服务器情况比较糟糕，CPU占用100% ，ssh也登录不进去，维持了一段时间后才进行重启，所以没有收集到最重要的崩溃之前的MySQL内部信息   整个的恢复过程用了6个小时</p>
<p><strong>这个时候，引发了我们的反思:</strong></p>
<p>1. 我们的MySQL压测模型没有针对不同版本的MySQL进行崩溃恢复压测  所以出现这个崩溃恢复的问题，我们只能补回来这个测试，针对不同版本的MySQL(MySQL 5.0.67 和MySQL5.1.xx)，需要进行相同TPS的场景下进行kill -9  pid (mysqld)的测试，掌握一手的崩溃恢复时间，为将来线上出现MySQL崩溃，做最好的准备</p>
<p>2. 我自己对MySQL InnoDB崩溃恢复的过程不是非常了解,导致MySQL崩溃之前没有去采集有参考价值的数值，这点需要加把劲</p>
<p>这一篇是前言，下一篇，我会对<strong>MySQL InnoDB的崩溃恢复过程</strong>做详细的介绍</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/mysql-innodb-%e5%b4%a9%e6%ba%83%e6%81%a2%e5%a4%8d%e8%bf%87%e7%a8%8b-%e5%89%8d%e8%a8%80/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>测试快速关闭innodb的方法</title>
		<link>http://dbahacker.com/mysql/innodb-fast-shutdown</link>
		<comments>http://dbahacker.com/mysql/innodb-fast-shutdown#comments</comments>
		<pubDate>Mon, 21 Jun 2010 07:31:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=122</guid>
		<description><![CDATA[Google docs 查看地址 http://docs.google.com/Doc?docid=0AR0iV03BDag2ZGRyMjI5cjdfODAxZnd6ejZ2Z3c&#38;hl=en pdf下载地址 _mysqlporformanceblog_innodb_ (1) 测试mysqlporformanceblog提供的减少关闭innodb时间的方法 经常发现一些MySQL镜像库的InnoDB的关闭时间会特别久，mysqlperformanceblog给出了一个不错的解决方案 How to decrease InnoDB shutdown times http://www.mysqlperformanceblog.com/2009/04/15/how-to-decrease-innodb-shutdown-times/ InnoDB关闭的过程解释 MySQL官方手册介绍 影响到InnoDB关闭的参数有 innodb_fast_shutdown 如果你把这个参数设置为0，InnoDB在关闭之前做一个完全净化和一个插入缓冲合并。这些操作要花几分钟时间，在极端情况下要几个小时。 如果你设置这个参数为1，InnoDB在关闭之时跳过这些操作。 默认值为1。 如果你设置这个值为2 (在Netware无此值)， InnoDB将刷新它的日志然后冷关机，仿佛MySQL崩溃一样。已提交的事务不会被丢失，但在下一次启动之时会做一个崩溃恢复。 innodb_max_dirty_pages_pct 这是一个范围从0到100的整数。默认是90。InnoDB中的主线程试着从缓冲池写页面，使得脏页（没有被写的页面）的百分比不超过这个值。如果你有SUPER权限，这个百分比可以在服务器运行时按下面来改变： SET GLOBAL innodb_max_dirty_pages_pct = value; 100423  0:10:18  InnoDB: Starting shutdown&#8230; 100423  0:10:20  InnoDB: Shutdown completed; log sequence number 0 4000976145 100423  0:10:20 [Note] /usr/sbin/mysqld: Shutdown complete 测试环境 [...]]]></description>
			<content:encoded><![CDATA[<div style="font-family: Verdana; font-size: 10pt; background-color: #ffffff; color: #000000; min-height: 1100px; counter-reset: __goog_page__ 0; line-height: normal; padding: 0px; margin: 6px;">
<div style="margin-top: 0px; margin-bottom: 0px;"><strong>Google docs 查看地址</strong> <a href="http://docs.google.com/Doc?docid=0AR0iV03BDag2ZGRyMjI5cjdfODAxZnd6ejZ2Z3c&amp;hl=en" target="_blank">http://docs.google.com/Doc?docid=0AR0iV03BDag2ZGRyMjI5cjdfODAxZnd6ejZ2Z3c&amp;hl=en</a></div>
<div style="margin-top: 0px; margin-bottom: 0px;"></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><strong>pdf下载地址</strong> <a href="http://dbahacker.com/wp-content/uploads/2010/06/mysqlporformanceblog_innodb_-1.pdf">_mysqlporformanceblog_innodb_ (1)</a></div>
<div style="margin-top: 0px; margin-bottom: 0px;"></div>
<div style="margin-top: 0px; margin-bottom: 0px;">测试mysqlporformanceblog提供的减少关闭innodb时间的方法</div>
<div style="margin-top: 0px; margin-bottom: 0px;"></div>
<div style="margin-top: 0px; margin-bottom: 0px;">经常发现一些MySQL镜像库的InnoDB的关闭时间会特别久，mysqlperformanceblog给出了一个不错的解决方案</div>
<div style="margin-top: 0px; margin-bottom: 0px;"><strong>How to decrease InnoDB shutdown times </strong><a id="ggx8" style="color: #551a8b;" title="http://www.mysqlperformanceblog.com/2009/04/15/how-to-decrease-innodb-shutdown-times/" href="http://www.mysqlperformanceblog.com/2009/04/15/how-to-decrease-innodb-shutdown-times/">http://www.mysqlperformanceblog.com/2009/04/15/how-to-decrease-innodb-shutdown-times/</a></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="font-size: small;"><strong>InnoDB关闭的过程解释</strong></span></p>
<p>MySQL官方手册介绍 影响到InnoDB关闭的参数有</p>
<p style="background-color: transparent; background-image: initial; border-color: initial; border-style: initial; vertical-align: baseline; margin: 0px;"><span style="font-family: verdana, arial, helvetica, sans-serif;"><span style="color: #555555;"><span style="background-image: initial; border-color: initial; border-style: initial; margin-left: 0px; margin-right: 0px; vertical-align: baseline;"><span style="font-size: x-small;">innodb_fast_shutdown</span></span></span></span></p>
<p style="background-color: transparent; background-image: initial; border-color: initial; border-style: initial; vertical-align: baseline; margin: 0px;"><span style="font-family: verdana, arial, helvetica, sans-serif;"><span style="color: #555555;"><span style="background-image: initial; border-color: initial; border-style: initial; margin-left: 0px; margin-right: 0px; vertical-align: baseline;"><span style="font-size: x-small;">如果你把这个参数设置为0，InnoDB在关闭之前做一个完全净化和一个插入缓冲合并。这些操作要花几分钟时间，在极端情况下要几个小时。</span></span></span></span></p>
<p style="background-color: transparent; background-image: initial; border-color: initial; border-style: initial; vertical-align: baseline; margin: 0px;"><span style="font-family: verdana, arial, helvetica, sans-serif;"><span style="color: #555555;"><span style="background-image: initial; border-color: initial; border-style: initial; margin-left: 0px; margin-right: 0px; vertical-align: baseline;"><span style="font-size: x-small;">如果你设置这个参数为1，InnoDB在关闭之时跳过这些操作。 默认值为1。</span></span></span></span></p>
<p style="background-color: transparent; background-image: initial; border-color: initial; border-style: initial; vertical-align: baseline; margin: 0px;"><span style="font-family: verdana, arial, helvetica, sans-serif;"><span style="color: #555555;"><span style="background-image: initial; border-color: initial; border-style: initial; margin-left: 0px; margin-right: 0px; vertical-align: baseline;"><span style="font-size: x-small;">如果你设置这个值为2 (在Netware无此值)， InnoDB将刷新它的日志然后冷关机，仿佛MySQL崩溃一样。已提交的事务不会被丢失，但在下一次启动之时会做一个崩溃恢复。</span></span></span></span></p>
<p><span style="font-size: x-small;"><br />
</span></p>
<p style="background-color: transparent; background-image: initial; border-color: initial; border-style: initial; vertical-align: baseline; margin: 0px;"><span style="font-family: verdana, arial, helvetica, sans-serif;"><span style="color: #555555;"><span style="background-image: initial; border-color: initial; border-style: initial; margin-left: 0px; margin-right: 0px; vertical-align: baseline;"><span style="font-size: x-small;">innodb_max_dirty_pages_pct</span></span></span></span></p>
<p style="background-color: transparent; background-image: initial; border-color: initial; border-style: initial; vertical-align: baseline; margin: 0px;"><span style="font-family: verdana, arial, helvetica, sans-serif;"><span style="color: #555555;"><span style="background-image: initial; border-color: initial; border-style: initial; margin-left: 0px; margin-right: 0px; vertical-align: baseline;"><span style="font-size: x-small;">这是一个范围从0到100的整数。默认是90。InnoDB中的主线程试着从缓冲池写页面，使得脏页（没有被写的页面）的百分比不超过这个值。如果你有SUPER权限，这个百分比可以在服务器运行时按下面来改变：</span></span></span></span></p>
<p><span style="color: #555555;"><span style="font-family: 'Courier New';"><span style="background-image: initial; border-color: initial; border-style: initial; margin-left: 0px; margin-right: 0px; vertical-align: baseline;"><span style="font-size: x-small;">SET GLOBAL innodb_max_dirty_pages_pct = </span><em><span style="font-size: x-small;">value</span></em><span style="font-size: x-small;">;</span></span></span></span><br />
<span style="font-size: x-small;"><br />
</span><span style="font-size: x-small;"><br />
</span></p>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="font-size: x-small;">100423  0:10:18  InnoDB: Starting shutdown&#8230;</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="font-size: x-small;">100423  0:10:20  InnoDB: Shutdown completed; log sequence number 0 4000976145</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="font-size: x-small;">100423  0:10:20 [Note] /usr/sbin/mysqld: Shutdown complete</span></div>
<p><span style="font-size: x-small;"><br />
</span></p>
<h3 style="font-size: 12pt;">测试环境</h3>
<div style="margin-top: 0px; margin-bottom: 0px;">1.在一个镜像库节点进行测试,innodb_buffer_pool_size=1G</div>
<div style="margin-top: 0px; margin-bottom: 0px;">2.在一个线上节点进行测试,碰巧这个节点要进行机架更换,所以可以趁机测试一把</div>
<p>innodb_buffer_pool_size=12G,线上环境和镜像环境还是有点不一样,没法让<span style="color: #274e13;">Innodb_buffer_pool_pages_dirty的值少于1000，虽然是大于1000，但关闭起来还是比较快速的</span></p>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="font-size: small;"><strong>测试过程</strong></span><br />
<strong>正常关闭的normal-shutdown.sh</strong></p>
<div style="margin-top: 0px; margin-bottom: 0px;"><strong><br />
</strong></p>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">#!/bin/bash</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">#正常关闭innodb</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">log=”normal-shutdown.log”</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">start_time=`date`</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">echo “start time:”$start_time &gt; $log</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">mysqladmin &#8211;defaults-file=db-32-1.cnf -uxxx -pxxx  ext  | grep dirty &gt;&gt; $log</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">mysqladmin &#8211;defaults-file=db-32-1.cnf -uxxx -pxxx shutdown</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">end_time=`date`</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">echo “end time:” $end_time &gt;&gt; $log</span></div>
<p>normal-shutdown.log 输出的日志如下</p></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #274e13;">start time:2010年 06月 18日 星期五 17:21:00 CST</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #274e13;">| Innodb_buffer_pool_pages_dirty    | 43492        |</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #274e13;">end time: 2010年 06月 18日 星期五 17:23:10 CST</span></div>
<p><strong>设置</strong><span style="font-family: 'courier new';"><span style="color: #38761d;"><strong>set global innodb_max_dirty_pages_pct =0的<span><span style="background-color: #ffffff;"><span style="color: #000000;">关闭方式</span></span></span></strong></span></span></p>
<div style="margin-top: 0px; margin-bottom: 0px;">首先执行 <span style="color: #38761d;">mysql &#8211;defaults-file=db-31-2.cnf -uxxx -pxxx -e” <span style="font-family: 'courier new';">set global innodb_max_dirty_pages_pct =0</span>“</span><br />
经过了大概3分钟后 Innodb_buffer_pool_pages_dirty的值少于1000</div>
<div style="margin-top: 0px; margin-bottom: 0px;">然后执行faster-shutdown.sh，生成faster-shutdown.log</div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">#!/bin/bash</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">log=”faster-shutdown.log”</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">start_time=`date`</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">echo “faster shutdown start time:”$start_time &gt;$log</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">mysqladmin &#8211;defaults-file=db-32-1.cnf -uxxx -pxxx  ext  | grep dirty &gt;&gt; $log</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">mysqladmin &#8211;defaults-file=db-32-1.cnf -uxxx -pxxx shutdown</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">end_time=`date`</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">echo “faster shutdown end time:” $end_time &gt;&gt;$log</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;">faster-shutdown.log的内容</div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">faster shutdown start time:2010年 06月 18日 星期五 17:47:08 CST</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">| Innodb_buffer_pool_pages_dirty    | 569        |</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #38761d;">faster shutdown end time: 2010年 06月 18日 星期五 17:47:12 CST</span></div>
<p><span style="font-size: small;"><strong>关闭时间比较</strong></span></p>
<table id="e605" style="font-size: 1em; line-height: inherit; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="3" bordercolor="#000000">
<tbody>
<tr style="text-align: left;">
<td width="33.333333333333336%"></td>
<td width="33.333333333333336%">正常关闭</td>
<td width="33.333333333333336%">快速关闭</td>
</tr>
<tr style="text-align: left;">
<td width="33.333333333333336%">Innodb_buffer_pool_pages_dirty</td>
<td width="33.333333333333336%">43492</td>
<td width="33.333333333333336%">569</td>
</tr>
<tr style="text-align: left;">
<td width="33.333333333333336%">关闭时间</td>
<td width="33.333333333333336%">2分10秒</td>
<td width="33.333333333333336%">4秒</td>
</tr>
</tbody>
</table>
<h3 style="font-size: 12pt;">结论</h3>
<div style="margin-top: 0px; margin-bottom: 0px;">日常维护中,可以使用<span style="font-family: 'courier new';"><span style="color: #38761d;">set global innodb_max_dirty_pages_pct =0,</span>让<span style="color: #38761d;">Innodb_buffer_pool_pages_dirty </span>的数值为一个较小的值,这样就可以减少在关闭mysql服务器中耗费在innodb的时间</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: 'courier new';">最终达到减少影响用户的时间</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;">参考资料</div>
<p><strong>InnoDB启动 </strong><a style="color: #551a8b;" href="http://dev.mysql.com/doc/refman/5.1/zh/storage-engines.html#innodb-start"><strong>http://dev.mysql.com/doc/refman/5.1/zh/storage-engines.html#innodb-start</strong></a><br />
<strong><br />
</strong></p>
<div style="margin-top: 0px; margin-bottom: 0px;"><strong>How to decrease InnoDB shutdown times </strong><a id="kp-." style="color: #551a8b;" title="http://www.mysqlperformanceblog.com/2009/04/15/how-to-decrease-innodb-shutdown-times/" href="http://www.mysqlperformanceblog.com/2009/04/15/how-to-decrease-innodb-shutdown-times/">http://www.mysqlperformanceblog.com/2009/04/15/how-to-decrease-innodb-shutdown-times/</a></div>
<p><strong>Dirty pages, fast shutdown, and write combining </strong><a style="color: #551a8b;" href="http://www.xaprb.com/blog/2010/05/25/dirty-pages-fast-shutdown-and-write-combining/">http://www.xaprb.com/blog/2010/05/25/dirty-pages-fast-shutdown-and-write-combining/</a></div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/innodb-fast-shutdown/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL5.1 InnoDB Plugin 启动信息详解 以及与MySQL5.0的InnoDB启动信息对比</title>
		<link>http://dbahacker.com/mysql/innodb-plugin-log-analyze</link>
		<comments>http://dbahacker.com/mysql/innodb-plugin-log-analyze#comments</comments>
		<pubDate>Wed, 09 Jun 2010 12:48:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=115</guid>
		<description><![CDATA[经过一段时间的测试,准备把MySQL 5.1 InnoDB Plugin部署到线上，今天发现MySQL 5.0 InnoDB 和MySQL5.1 InnoDB Plugin启动是有点区别的，这里做一个整理 5.0MySQL 的版本信息 mysql&#62; show variables like &#8217;%version%&#8217;; +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+ &#124; Variable_name           &#124; Value                       &#124; +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+ &#124; protocol_version        &#124; 10                          &#124; &#124; version                 &#124; 5.0.38-Debian_3netease5-log &#124; &#124; version_comment         &#124; Debian etch distribution    &#124; &#124; version_compile_machine &#124; x86_64                      &#124; &#124; version_compile_os      &#124; pc-linux-gnu                &#124; +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+ 5 rows in set (0.01 sec) 启动的日志信息 InnoDB: The first specified data file xxx//ibdata1 did not exist: InnoDB: a new database to be created! 100609 19:18:50  InnoDB: Setting file xxx//ibdata1 size to 32 MB InnoDB: Database physically writes the file full: wait&#8230; 100609 19:18:51  InnoDB: Log file xxx/ib_logfile0 did not exist: new to be created InnoDB: Setting log file xxx/ib_logfile0 size to 128 MB InnoDB: Database physically writes the file full: wait&#8230; InnoDB: Progress in MB: 100 100609 19:18:53  InnoDB: Log file xxx/ib_logfile1 did not exist: new to be created InnoDB: Setting log file xxxx/ib_logfile1 size to 128 MB InnoDB: Database physically writes the file full: wait&#8230; InnoDB: Progress in MB: 100 InnoDB: Doublewrite buffer not found: creating new InnoDB: Doublewrite buffer created InnoDB: Creating foreign key constraint system tables InnoDB: Foreign key constraint system tables created 100609 19:18:57  InnoDB: Started; log sequence number 0 0 100609 19:18:57 [Note] /usr/sbin/mysqld: ready for connections. Version: &#8217;5.0.38-Debian_3netease5-log&#8217;  socket: xxx/mysqld.sock&#8217;  port: 4591  Debian etch distribution MySQL 5.1 的版本信息 mysql&#62;  show variables like &#8217;%version%&#8217;; +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ &#124; Variable_name           &#124; Value               &#124; +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ &#124; innodb_version          &#124; 1.0.6-unknown       &#124; ##这个是InnoDB Plugin的新信息 &#124; protocol_version        &#124; 10                  &#124; &#124; version                 &#124; 5.1.45-log          &#124; &#124; version_comment         &#124; Source distribution &#124; &#124; version_compile_machine &#124; x86_64              &#124; &#124; version_compile_os      &#124; unknown-linux-gnu   &#124; +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ MySQL5.1 InnoDB Plugin启动日志信息，多了很多内容，下面逐一介绍 InnoDB: The InnoDB memory heap is disabled InnoDB: Mutexes and rw_locks use GCC atomic builtins InnoDB: The first specified data file ./ibdata1 did not exist: InnoDB: a new database to be created! 100609 17:17:11  InnoDB: Setting file ./ibdata1 size to 512 MB InnoDB: Database physically writes the file full: wait&#8230; InnoDB: Progress in MB: 100 200 300 400 500 100609 17:17:15  InnoDB: Log file xxx/ib_logfile0 did not exist: new to be created InnoDB: Setting log file [...]]]></description>
			<content:encoded><![CDATA[<p>经过一段时间的测试,准备把MySQL 5.1 InnoDB Plugin部署到线上，今天发现MySQL 5.0 InnoDB 和MySQL5.1 InnoDB Plugin启动是有点区别的，这里做一个整理</p>
<p>5.0MySQL 的版本信息</p>
<blockquote><p>mysql&gt; show variables like &#8217;%version%&#8217;;</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</p>
<p>| Variable_name           | Value                       |</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</p>
<p>| protocol_version        | 10                          |</p>
<p>| version                 | 5.0.38-Debian_3netease5-log |</p>
<p>| version_comment         | Debian etch distribution    |</p>
<p>| version_compile_machine | x86_64                      |</p>
<p>| version_compile_os      | pc-linux-gnu                |</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</p>
<p>5 rows in set (0.01 sec)</p></blockquote>
<p>启动的日志信息</p>
<blockquote><p>InnoDB: The first specified data file xxx//ibdata1 did not exist:</p>
<p>InnoDB: a new database to be created!</p>
<p>100609 19:18:50  InnoDB: Setting file xxx//ibdata1 size to 32 MB</p>
<p>InnoDB: Database physically writes the file full: wait&#8230;</p>
<p>100609 19:18:51  InnoDB: Log file xxx/ib_logfile0 did not exist: new to be created</p>
<p>InnoDB: Setting log file xxx/ib_logfile0 size to 128 MB</p>
<p>InnoDB: Database physically writes the file full: wait&#8230;</p>
<p>InnoDB: Progress in MB: 100</p>
<p>100609 19:18:53  InnoDB: Log file xxx/ib_logfile1 did not exist: new to be created</p>
<p>InnoDB: Setting log file xxxx/ib_logfile1 size to 128 MB</p>
<p>InnoDB: Database physically writes the file full: wait&#8230;</p>
<p>InnoDB: Progress in MB: 100</p>
<p>InnoDB: Doublewrite buffer not found: creating new</p>
<p>InnoDB: Doublewrite buffer created</p>
<p>InnoDB: Creating foreign key constraint system tables</p>
<p>InnoDB: Foreign key constraint system tables created</p>
<p>100609 19:18:57  InnoDB: Started; log sequence number 0 0</p>
<p>100609 19:18:57 [Note] /usr/sbin/mysqld: ready for connections.</p>
<p>Version: &#8217;5.0.38-Debian_3netease5-log&#8217;  socket: xxx/mysqld.sock&#8217;  port: 4591  Debian etch distribution</p></blockquote>
<p>MySQL 5.1 的版本信息</p>
<blockquote><p>mysql&gt;  show variables like &#8217;%version%&#8217;;</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</p>
<p>| Variable_name           | Value               |</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</p>
<p>| innodb_version          | 1.0.6-unknown       | ##这个是InnoDB Plugin的新信息</p>
<p>| protocol_version        | 10                  |</p>
<p>| version                 | 5.1.45-log          |</p>
<p>| version_comment         | Source distribution |</p>
<p>| version_compile_machine | x86_64              |</p>
<p>| version_compile_os      | unknown-linux-gnu   |</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</p></blockquote>
<p>MySQL5.1 InnoDB Plugin启动日志信息，多了很多内容，下面逐一介绍</p>
<blockquote><p>InnoDB: The InnoDB memory heap is disabled</p>
<p>InnoDB: Mutexes and rw_locks use GCC atomic builtins</p>
<p>InnoDB: The first specified data file ./ibdata1 did not exist:</p>
<p>InnoDB: a new database to be created!</p>
<p>100609 17:17:11  InnoDB: Setting file ./ibdata1 size to 512 MB</p>
<p>InnoDB: Database physically writes the file full: wait&#8230;</p>
<p>InnoDB: Progress in MB: 100 200 300 400 500</p>
<p>100609 17:17:15  InnoDB: Log file xxx/ib_logfile0 did not exist: new to be created</p>
<p>InnoDB: Setting log file  xxx/ib_logfile0 size to 512 MB</p>
<p>InnoDB: Database physically writes the file full: wait&#8230;</p>
<p>InnoDB: Progress in MB: 100 200 300 400 500</p>
<p>100609 17:17:21  InnoDB: Log file xxx/ib_logfile1 did not exist: new to be created</p>
<p>InnoDB: Setting log file xxxx/ib_logfile1 size to 512 MB</p>
<p>InnoDB: Database physically writes the file full: wait&#8230;</p>
<p>InnoDB: Progress in MB: 100 200 300 400 500</p>
<p>InnoDB: Doublewrite buffer not found: creating new</p>
<p>InnoDB: Doublewrite buffer created</p>
<p>InnoDB: Creating foreign key constraint system tables</p>
<p>InnoDB: Foreign key constraint system tables created</p>
<p>100609 17:17:26 InnoDB Plugin 1.0.6-unknown started; log sequence number 0</p>
<p>100609 17:17:28 [Note] Event Scheduler: Loaded 0 events</p>
<p>100609 17:17:28 [Note] /usr/xtradb/libexec/mysqld: ready for connections.</p>
<p>Version: &#8217;5.1.45-log&#8217;  socket: &#8217;xxx/mysqld.sock&#8217;  port: 4331  Source distribution</p></blockquote>
<p>InnoDB: The InnoDB memory heap is disabled</p>
<p>是因为使用了操作系统的内存分配器,所以就禁用了InnoDB的内置内存分配器</p>
<blockquote><p>mysql&gt; show variables like &#8217;%malloc%&#8217;;</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+</p>
<p>| Variable_name         | Value |</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+</p>
<p>| innodb_use_sys_malloc | ON    |</p>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+</p>
<p>1 row in set (0.00 sec)</p></blockquote>
<p>而在5.0里面执行是为空结果的，关于这个innodb_use_sys_malloc，具体可以参阅<a href="http://www.innodb.com/doc/innodb_plugin-1.0-doc-single/innodb-plugin.html#innodb-performance-use_sys_malloc">InooDB的官方介绍</a></p>
<p>Mutexes and rw_locks use GCC atomic builtins</p>
<p>对比以往的版本,InnoDB Plugin 1.0.3之后的版本 使用了GCC atomic builtins来执行互斥和读写锁,性能会比以往使用的pthread_mutex_t要高效</p>
<p>参见 <a href="http://www.innodb.com/wp/support/tips/atomics/">InnoDB Plugin: Enabling GCC atomic built-in functions for InnoDB rw-locks</a><br />
InnoDB: The first specified data file ./ibdata1 did not exist:</p>
<p>InnoDB: a new database to be created!</p>
<p>第一次启动mysql，因为默认的是innodb引擎，所以会自动创建一个test</p>
<blockquote><p>InnoDB: Doublewrite buffer not found: creating new</p>
<p>InnoDB: Doublewrite buffer created</p></blockquote>
<p>什么是Doublewrite?</p>
<p>InnoDB将BP中的Dirty Page刷（flush）到磁盘上时，首先会将Page刷到InnoDB tablespace的一个区域中，我们称该区域为Double write Buffer。在向Double write Buffer写入成功后，再择机将数据拷贝到正在的数据文件对应的位置。</p>
<p>更多详细的信息可以看看performace blog 的对<a href="http://www.mysqlperformanceblog.com/2006/08/04/innodb-double-write/#more-72">doublewrite的介绍</a></p>
<p>或者是苏普的对<a href="http://www.orczhou.com/index.php/2010/02/innodb-double-write/">Doublewrite整理 InnoDB Double write</a></p>
<p>参考资料</p>
<p>InnoDB Plugin: Enabling GCC atomic built-in functions for InnoDB rw-locks</p>
<p><a href="http://www.innodb.com/wp/support/tips/atomics/">http://www.innodb.com/wp/support/tips/atomics/</a></p>
<p>InnoDB Plugin 1.0 for MySQL 5.1 User’s Guide</p>
<p><a href="http://www.innodb.com/doc/innodb_plugin-1.0-doc-single/innodb-plugin.html#innodb-performance-use_sys_malloc">http://www.innodb.com/doc/innodb_plugin-1.0-doc-single/innodb-plugin.html#innodb-performance-use_sys_malloc</a></p>
<p>Innodb Double Write</p>
<p><a href="http://www.mysqlperformanceblog.com/2006/08/04/innodb-double-write/#more-72">http://www.mysqlperformanceblog.com/2006/08/04/innodb-double-write/#more-72</a></p>
<p>转载烦请保留原文连接 http://dbahacker.com/mysql/<span id="editable-post-name" style="outline-width: 0px; outline-style: initial; outline-color: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #fffbcc; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;" title="点击编辑这部分固定链接">innodb-plugin-log-analyze</span></p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/innodb-plugin-log-analyze/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Master-Slave的一个read log event 错误处理</title>
		<link>http://dbahacker.com/mysql/master-slave-read-log-event</link>
		<comments>http://dbahacker.com/mysql/master-slave-read-log-event#comments</comments>
		<pubDate>Tue, 08 Jun 2010 06:10:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=111</guid>
		<description><![CDATA[Master-Slave的一个read log event 错误处理 现在简单介绍一下几个节点的情况 B服务器上面有一个B1节点，是MySQL5.0版本，普通InnoDB的表 C服务器上面有两个测试节点（C1，C2）, 它们是A服务器上面的A1节点的slave,C1，C2，都是使用XtraDB压缩功能的表 也就是 A为Master,有3个Slave(B1,C1,C2) 因为某些原因,C2的slave 复制出现了问题,而C1是没有问题的，当时候采取了以下措施 1.停止C1,C2的slave,使用mysqladmin shutdown来关闭C1,C2 2.删掉C2的数据目录等，只留下my.cnf 3.把C1的数据目录等都拷贝到C2目录下 4.启动C1,C2 这时候发现C2的mysqd.log 里面有了这样的内容 100608 12:44:14 [Note] Slave: received end packet from server, apparent master shutdown: 100608 12:44:14 [Note] Slave I/O thread: Failed reading log event, reconnecting to retry, log &#8216;mysql-bin.007817&#8242; at postion 86542498 100608 12:44:15 [Note] Slave I/O thread [...]]]></description>
			<content:encoded><![CDATA[<p>Master-Slave的一个read log event 错误处理</p>
<p>现在简单介绍一下几个节点的情况<br />
B服务器上面有一个B1节点，是MySQL5.0版本，普通InnoDB的表<br />
C服务器上面有两个测试节点（C1，C2）,<br />
它们是A服务器上面的A1节点的slave,C1，C2，都是使用XtraDB压缩功能的表</p>
<p>也就是 A为Master,有3个Slave(B1,C1,C2)</p>
<p>因为某些原因,C2的slave 复制出现了问题,而C1是没有问题的，当时候采取了以下措施<br />
1.停止C1,C2的slave,使用mysqladmin shutdown来关闭C1,C2<br />
2.删掉C2的数据目录等，只留下my.cnf<br />
3.把C1的数据目录等都拷贝到C2目录下<br />
4.启动C1,C2</p>
<p>这时候发现C2的mysqd.log 里面有了这样的内容</p>
<blockquote><p>100608 12:44:14 [Note] Slave: received end packet from server, apparent master shutdown:<br />
100608 12:44:14 [Note] Slave I/O thread: Failed reading log event, reconnecting to retry, log &#8216;mysql-bin.007817&#8242; at postion 86542498<br />
100608 12:44:15 [Note] Slave I/O thread killed while reading event</p></blockquote>
<p>同时在C2里面执行show slave status \G的时候,Seconds_behind_master = 会出现落后的秒数，但连续的执行show slave status 的时候就会看到有NULL的信息</p>
<p>mysqlperformanceblog有一篇文章是提到过是server-id的问题 http://www.mysqlperformanceblog.com/2008/06/04/confusing-mysql-replication-error-message/<br />
但是我的3个slave的server-id都是不一样的，和master的server-id也是不一样的</p>
<p>最后的解决方法是尝试了一把把C2的server-id改成新的值，重启mysql,stop slave ;start slave;show slave status \G后发现复制正常了，不知道是否和我直接copy C1的数据库等文件过来是否有关</p>
<p>参考文献/文章</p>
<p><a href="http://www.mysqlperformanceblog.com/2008/06/04/confusing-mysql-replication-error-message/"> Confusing MySQL Replication Error Message</a> http://www.mysqlperformanceblog.com/2008/06/04/confusing-mysql-replication-error-message/<br />
<a href="http://bugs.mysql.com/bug.php?id=9325"> Many Errors “Slave: received end packet from server” </a> http://bugs.mysql.com/bug.php?id=9325</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/mysql/master-slave-read-log-event/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

