设为首页 收藏本站
查看: 518|回复: 0

[经验分享] mysql 8小时连接池异常和解决方法

[复制链接]

尚未签到

发表于 2016-10-17 06:45:37 | 显示全部楼层 |阅读模式
MySQL 的默认设置下,当一个连接的空闲时间超过8小时后,MySQL 就会断开该连接,而 c3p0连接池则以为该被断开的连接依然有效。在这种情况下,如果客户端代码向 c3p0连接池请求连接的话,连接池就会把已经失效的连接返回给客户端,客户端在使用该失效连接的时候即抛出异常。
解决这个问题的办法有三种:
1. 增加 MySQL 的 wait_timeout 属性的值。
修改<wbr><span style="font-style: italic;">/etc/mysql/my.cnf</span><wbr>文件,在[mysqld] 节中设置:<br><div style="border-top-width: 0.5pt; border-right-width: 0.5pt; border-bottom-width: 0.5pt; border-left-width: 0.5pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-image: initial; padding-top: 4px; padding-right: 5.4pt; padding-bottom: 4px; padding-left: 5.4pt; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: rgb(230, 230, 230); width: 659px; background-position: 0% 50%; background-repeat: repeat repeat;"><div><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><span style="color: rgb(0, 0, 0);">#Set a connection to wait<wbr></wbr></span><span style="color: rgb(0, 0, 0);">8</span><wbr><span style="color: rgb(0, 0, 0);">hours in idle status.<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr>wait_timeout<wbr></wbr></wbr></span><span style="color: rgb(0, 0, 0);">=</span><wbr><span style="color: rgb(0, 0, 0);">86400</span></wbr></wbr></wbr></div></div>2. 减少连接池内连接的生存周期,使之小于上一项中所设置的 wait_timeout 的值。<br>修改 c3p0 的配置文件,设置:<br><div style="border-top-width: 0.5pt; border-right-width: 0.5pt; border-bottom-width: 0.5pt; border-left-width: 0.5pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-image: initial; padding-top: 4px; padding-right: 5.4pt; padding-bottom: 4px; padding-left: 5.4pt; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: rgb(230, 230, 230); width: 659px; background-position: 0% 50%; background-repeat: repeat repeat;"><div><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><span style="color: rgb(0, 0, 0);">#How long to keep unused connections around(in seconds)<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr># Note: MySQL times out idle connectionsafter<wbr></wbr></wbr></span><span style="color: rgb(0, 0, 0);">8</span><wbr><span style="color: rgb(0, 0, 0);">hours(</span><wbr><span style="color: rgb(0, 0, 0);">28</span><wbr><span style="color: rgb(0, 0, 0);">,</span><wbr><span style="color: rgb(0, 0, 0);">800</span><wbr><span style="color: rgb(0, 0, 0);">seconds)<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr># so ensure this value is below MySQL idletimeout<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr>cpool.maxIdleTime</wbr></wbr></span><wbr><span style="color: rgb(0, 0, 0);">=</span><wbr><span style="color: rgb(0, 0, 0);">25200</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></div></div>在 Spring 的配置文件中:<br><div style="border-top-width: 0.5pt; border-right-width: 0.5pt; border-bottom-width: 0.5pt; border-left-width: 0.5pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-image: initial; padding-top: 4px; padding-right: 5.4pt; padding-bottom: 4px; padding-left: 5.4pt; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: rgb(230, 230, 230); width: 659px; background-position: 0% 50%; background-repeat: repeat repeat;"><div><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><span style="color: rgb(0, 0, 255);">&lt;</span><wbr><span style="color: rgb(128, 0, 0);">bean<wbr></wbr></span><span style="color: rgb(255, 0, 0);">id</span><wbr><span style="color: rgb(0, 0, 255);">="dataSource"</span><wbr><span style="color: rgb(255, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr>class</wbr></wbr></wbr></wbr></wbr></span><wbr><span style="color: rgb(0, 0, 255);">="com.mchange.v2.c3p0.ComboPooledDataSource"</span><wbr><span style="color: rgb(0, 0, 255);">&gt;</span><wbr><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></span><wbr><span style="color: rgb(0, 0, 255);">&lt;</span><wbr><span style="color: rgb(128, 0, 0);">property<wbr></wbr></span><span style="color: rgb(255, 0, 0);">name</span><wbr><span style="color: rgb(0, 0, 255);">="maxIdleTime"</span><wbr><span style="color: rgb(255, 0, 0);">value</span><wbr><span style="color: rgb(0, 0, 255);">="${cpool.maxIdleTime}"</span><wbr><span style="color: rgb(0, 0, 255);">/&gt;</span><wbr><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></span><wbr><span style="color: rgb(0, 128, 0);">&lt;!--</span><wbr><span style="color: rgb(0, 128, 0);">otherproperties<wbr></wbr></span><span style="color: rgb(0, 128, 0);">--&gt;</span><wbr><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr></wbr></span><span style="color: rgb(0, 0, 255);">&lt;/</span><wbr><span style="color: rgb(128, 0, 0);">bean</span><wbr><span style="color: rgb(0, 0, 255);">&gt;</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></div></div>3. 定期使用连接池内的连接,使得它们不会因为闲置超时而被 MySQL 断开。<br>修改 c3p0 的配置文件,设置:<br><div style="border-top-width: 0.5pt; border-right-width: 0.5pt; border-bottom-width: 0.5pt; border-left-width: 0.5pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-image: initial; padding-top: 4px; padding-right: 5.4pt; padding-bottom: 4px; padding-left: 5.4pt; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: rgb(230, 230, 230); width: 659px; background-position: 0% 50%; background-repeat: repeat repeat;"><div><pre style="white-space: pre-wrap; word-wrap: break-word;"><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><span style="color: rgb(0, 0, 0);"># Prevent MySQL raise exception after a long idle time<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法">cpool.preferredTestQuery</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">'SELECT </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">'<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法">cpool.idleConnectionTestPeriod<wbr></wbr></span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">18000</span><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法">cpool.testConnectionOnCheckout<wbr></wbr></span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">true</span></pre></div></div>修改 Spring 的配置文件:<br><div style="border-top-width: 0.5pt; border-right-width: 0.5pt; border-bottom-width: 0.5pt; border-left-width: 0.5pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-image: initial; padding-top: 4px; padding-right: 5.4pt; padding-bottom: 4px; padding-left: 5.4pt; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: rgb(230, 230, 230); width: 659px; background-position: 0% 50%; background-repeat: repeat repeat;"><div><pre style="white-space: pre-wrap; word-wrap: break-word;"><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="dataSource"</span><span style="color: rgb(255, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr>  class</wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">="com.mchange.v2.c3p0.ComboPooledDataSource"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="preferredTestQuery"</span><span style="color: rgb(255, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>  value</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">="${cpool.preferredTestQuery}"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="idleConnectionTestPeriod<wbr>"</wbr></span><span style="color: rgb(255, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>  value</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">="${cpool.idleConnectionTestPeriod<wbr>}"</wbr></span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="testConnectionOnCheckout<wbr>"</wbr></span><span style="color: rgb(255, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>  value</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">="${cpool.testConnectionOnCheckout<wbr>}"</wbr></span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> other properties </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br></span></pre></div></div><br>附:以下 awk 脚本可以用以将 c3p0.properties 文件中的属性设置转换成为applicationContext.xml 中 数据库连接池 DataSource 所需的 XML 元素形式。<br><div style="border-top-width: 0.5pt; border-right-width: 0.5pt; border-bottom-width: 0.5pt; border-left-width: 0.5pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-image: initial; padding-top: 4px; padding-right: 5.4pt; padding-bottom: 4px; padding-left: 5.4pt; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: rgb(230, 230, 230); width: 659px; background-position: 0% 50%; background-repeat: repeat repeat;"><div><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><span style="color: rgb(0, 0, 0);">#</span><wbr><span style="color: rgb(0, 0, 0);">!</span><wbr><span style="color: rgb(0, 0, 0);">/</span><wbr><span style="color: rgb(0, 0, 0);">bin</span><wbr><span style="color: rgb(0, 0, 0);">/</span><wbr><span style="color: rgb(0, 0, 0);">awk<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr>BEGIN {<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr>FS</wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><wbr><span style="color: rgb(0, 0, 0);">=</span><wbr><span style="color: rgb(0, 0, 0);">"</span><wbr><span style="color: rgb(0, 0, 0);">=</span><wbr><span style="color: rgb(0, 0, 0);">"</span><wbr><span style="color: rgb(0, 0, 0);">;</span><wbr><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr>}<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr>{<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><wbr><span style="color: rgb(0, 0, 255);">if</span><wbr><span style="color: rgb(0, 0, 0);">(</span><wbr><span style="color: rgb(0, 0, 0);">NF<wbr></wbr></span><span style="color: rgb(0, 0, 0);">==</span><wbr><span style="color: rgb(0, 0, 0);">2</span><wbr><span style="color: rgb(0, 0, 0);">)</span><wbr><span style="color: rgb(0, 0, 0);">{<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><wbr><span style="color: rgb(0, 0, 255);">if</span><wbr><span style="color: rgb(0, 0, 0);">((</span><wbr><span style="color: rgb(0, 0, 0);">x</span><wbr><span style="color: rgb(0, 0, 0);">=</span><wbr><span style="color: rgb(0, 0, 0);">index</span><wbr><span style="color: rgb(0, 0, 0);">($</span><wbr><span style="color: rgb(0, 0, 0);">1</span><wbr><span style="color: rgb(0, 0, 0);">,</span><wbr><span style="color: rgb(0, 0, 0);">"</span><wbr><span style="color: rgb(0, 0, 0);">.</span><wbr><span style="color: rgb(0, 0, 0);">"</span><wbr><span style="color: rgb(0, 0, 0);">))</span><wbr><span style="color: rgb(0, 0, 0);">&gt;</span><wbr><span style="color: rgb(0, 0, 0);">0</span><wbr><span style="color: rgb(0, 0, 0);">)</span><wbr><span style="color: rgb(0, 0, 0);">{<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>property_name<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 0);">=</span><wbr><span style="color: rgb(0, 0, 0);">substr</span><wbr><span style="color: rgb(0, 0, 0);">($</span><wbr><span style="color: rgb(0, 0, 0);">1</span><wbr><span style="color: rgb(0, 0, 0);">,</span><wbr><span style="color: rgb(0, 0, 0);">x</span><wbr><span style="color: rgb(0, 0, 0);">+</span><wbr><span style="color: rgb(0, 0, 0);">1</span><wbr><span style="color: rgb(0, 0, 0);">,</span><wbr><span style="color: rgb(0, 0, 0);">length</span><wbr><span style="color: rgb(0, 0, 0);">($</span><wbr><span style="color: rgb(0, 0, 0);">1</span><wbr><span style="color: rgb(0, 0, 0);">));</span><wbr><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 255);">else</span><wbr><span style="color: rgb(0, 0, 0);">{<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>property_name<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color: rgb(0, 0, 0);">=</span><wbr><span style="color: rgb(0, 0, 0);">$</span><wbr><span style="color: rgb(0, 0, 0);">1</span><wbr><span style="color: rgb(0, 0, 0);">;</span><wbr><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>printf</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><wbr><span style="color: rgb(0, 0, 0);">(</span><wbr><span style="color: rgb(0, 0, 0);">"</span><wbr><span style="color: rgb(0, 0, 0);">&lt;property name="%s"value="${%s}"/&gt;<wbr></wbr></span><span style="color: rgb(0, 0, 0);">"</span><wbr><span style="color: rgb(0, 0, 0);">,</span><wbr><span style="color: rgb(0, 0, 0);">property_name</span><wbr><span style="color: rgb(0, 0, 0);">,</span><wbr><span style="color: rgb(0, 0, 0);">$</span><wbr><span style="color: rgb(0, 0, 0);">1</span><wbr><span style="color: rgb(0, 0, 0);">);</span><wbr><span style="color: rgb(0, 0, 0);"><br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr><wbr><wbr><wbr><wbr>}<br><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial;" title="mysql&lt;wbr&gt;8小时连接池异常和解决方法"><wbr>}</wbr></wbr></wbr></wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></div></div></wbr></wbr>



对MySQL server hasgone away错误最常见的原因是服务器超时了并且关闭了连接。缺省地,如果没有事情发生,服务器在8个小时后关闭连接。可在启动mysqld时通过设置wait_timeout变量改变时间限制。
<wbr><wbr><wbr><wbr><wbr><wbr>具体操作如下:<br><wbr><wbr><wbr><wbr><wbr><wbr>在MS-DOC 中 MySql 5.0/bin 目录下运行 :mysqld --verbose--help<wbr><wbr>,得到 MySql 的参数配置。从中看到wait_timeout = 28800 ,也就是8小时。如果超过 8 小时,没有对数据库进行操作,数据连接就会自动断开。<br><br><wbr><wbr><wbr><wbr>解决方法一:<br><wbr><wbr><wbr><wbr>可以在 my.ini文件中启动项中添加<wbr><wbr>wait_timeout = 86400任意值来设置等待时间。</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-287094-1-1.html 上篇帖子: 手把手教你如何搭建PHP本地测试环境和MYSQL数据库的建立和使用 下篇帖子: MySQL 查询优化器(转自Popgo的博客)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表