﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-happy everyday-随笔分类-mysql</title><link>http://www.blogjava.net/smallfa/category/29723.html</link><description>上进、向上、乐观、健康、相信一切皆有可能</description><language>zh-cn</language><lastBuildDate>Thu, 09 Sep 2010 04:51:46 GMT</lastBuildDate><pubDate>Thu, 09 Sep 2010 04:51:46 GMT</pubDate><ttl>60</ttl><item><title>Communications link failure</title><link>http://www.blogjava.net/smallfa/archive/2010/09/08/331369.html</link><dc:creator>smallfa</dc:creator><author>smallfa</author><pubDate>Wed, 08 Sep 2010 01:29:00 GMT</pubDate><guid>http://www.blogjava.net/smallfa/archive/2010/09/08/331369.html</guid><wfw:comment>http://www.blogjava.net/smallfa/comments/331369.html</wfw:comment><comments>http://www.blogjava.net/smallfa/archive/2010/09/08/331369.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/smallfa/comments/commentRss/331369.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/smallfa/services/trackbacks/331369.html</trackback:ping><description><![CDATA[Communications link failure，The last packet successfully received from
the server was *** millisecond ago.The last packet successfully sent to
the server was *** millisecond ago。<br />
<br />
<div class="blogstory">
<p>最近做测试，发现Mysql 过一段时间会无法连接，导致数据库数据不一至，极其郁闷。</p>
<p>下面是转一哥门的</p>
<p>使用Connector/J连接MySQL数据库，程序运行较长时间后就会报以下错误：</p>
<p>Communications link failure，The last packet successfully received
from the server was *** millisecond ago.The last packet successfully
sent to the server was ***&nbsp; millisecond ago。</p>
<p>其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。</p>
<p>后来查了一些资料，才发现遇到这个问题的人还真不少，大部分都是使用连接池方式时才会出现这个问题，短连接应该很难出现这个问题。这个问题的原因：</p>
<p>MySQL服务器默认的&#8220;wait_timeout&#8221;是28800秒即8小时，意味着如果一个连接的空闲时间超过8个小时，MySQL将自动断开该连接，而连接池却认为该连接还是有效的(因为并未校验连接的有效性)，当应用申请使用该连接时，就会导致上面的报错。</p>
<p>1.按照错误的提示，可以在JDBC
URL中使用autoReconnect属性，实际测试时使用了autoReconnect=true&amp;
failOverReadOnly=false，不过并未起作用，使用的是5.1版本，可能真像网上所说的只对4之前的版本有效。</p>
<p>2.没办法，只能修改MySQL的参数了，wait_timeout最大为31536000即1年，在my.cnf中加入：</p>
<p>[mysqld]</p>
<p>wait_timeout=31536000</p>
<p>interactive_timeout=31536000</p>
<p>重启生效，需要同时修改这两个参数。</p>
<p><br />
本文来自CSDN博客，转载请标明出处：<a href="http://blog.csdn.net/cau99/archive/2009/12/11/4987760.aspx">http://blog.csdn.net/cau99/archive/2009/12/11/4987760.aspx</a></p>
</div>
<img src ="http://www.blogjava.net/smallfa/aggbug/331369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/smallfa/" target="_blank">smallfa</a> 2010-09-08 09:29 <a href="http://www.blogjava.net/smallfa/archive/2010/09/08/331369.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql 时间</title><link>http://www.blogjava.net/smallfa/archive/2010/08/04/327916.html</link><dc:creator>smallfa</dc:creator><author>smallfa</author><pubDate>Wed, 04 Aug 2010 03:40:00 GMT</pubDate><guid>http://www.blogjava.net/smallfa/archive/2010/08/04/327916.html</guid><wfw:comment>http://www.blogjava.net/smallfa/comments/327916.html</wfw:comment><comments>http://www.blogjava.net/smallfa/archive/2010/08/04/327916.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/smallfa/comments/commentRss/327916.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/smallfa/services/trackbacks/327916.html</trackback:ping><description><![CDATA[当月第一天&nbsp;&nbsp; select&nbsp; timestamp(concat(year(curdate()),'-',month(curdate()),'-','1'))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如2010-08-01 00:00:00<br />
当前时间&nbsp; select now() <br />
<br />
<img src ="http://www.blogjava.net/smallfa/aggbug/327916.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/smallfa/" target="_blank">smallfa</a> 2010-08-04 11:40 <a href="http://www.blogjava.net/smallfa/archive/2010/08/04/327916.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>