Mysql 8小时的解决方案

2016-05-12  本文已影响0人  no才

程序报错信息

The last packet successfully received from the server was 34,132 milliseconds ago.  The last packet 
……

问题描述

连接池保留了连接,但是mysql数据库已经回收了连接

解决方案

  1. 程序连接池配置
    • 如果使用的是JDBC,在JDBC URL上添加?autoReconnect=true
jdbc:mysql://10.10.10.10:3306/mydb?autoReconnect=true
<bean id="vrsRankDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${countNew.jdbc.url}" />
    <property name="username" value="${countNew.jdbc.user}" />
    <property name="password" value="${countNew.jdbc.pwd}" />
    <property name="validationQuery" value="SELECT 1" />
    <property name="testOnBorrow" value="true"/>
</bean>
<bean name="cacheCloudDB" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driver}"/>
    <property name="jdbcUrl" value="${cache.url}"/>
    <property name="user" value="${cache.user}"/>
    <property name="password" value="${cache.password}"/>
    <property name="initialPoolSize" value="10"/>
    <property name="maxPoolSize" value="${cache.maxPoolSize}"/>
    <property name="testConnectionOnCheckin" value="false"/>
    <property name="testConnectionOnCheckout" value="true"/>
    <property name="preferredTestQuery" value="SELECT 1"/>
</bean>
  1. 修改MySQL的参数.
    在/etc/my.cnf 添加
[mysqld]
wait_timeout=31536000
interactive_timeout=31536000
上一篇下一篇

猜你喜欢

热点阅读