mysql重连,连接丢失:The last packet successfully received
2016-03-21 00:00
1671 查看
摘要: mysql重连,连接丢失:The last packet successfully received
The last packet successfully received from the server was 77,150,600 milliseconds ago. The last packet sent successfully to the server was 77,150,601 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 77,150,600 milliseconds ago. The last packet sent successfully to the server was 77,150,601 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
###############################################################################
对于tomcat的server.xml中使用的连接池,http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html,http://commons.apache.org/dbcp/configuration.html使用DBCP的连接池可以采用
<Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8"
username="root" password="test" maxActive="500" maxIdle="10"
maxWait="-1" timeBetweenEvictionRunsMillis="10000" minEvictableIdleTimeMillis="10000" />
The last packet successfully received from the server was 77,150,600 milliseconds ago. The last packet sent successfully to the server was 77,150,601 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 77,150,600 milliseconds ago. The last packet sent successfully to the server was 77,150,601 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
###############################################################################
如果使用的是JDBC,在JDBC URL上添加?autoReconnect=true
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk&autoReconnect=true&failOverReadOnly=false如果是在Spring中使用c3p0连接池,则在定义datasource的时候,添加属性testConnectionOnCheckin和testConnectionOnCheckout
<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>如果是在Spring中使用DBCP连接池,在定义datasource增加属性validationQuery和testOnBorrow
<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>对于tomcat的server.xml中使用的连接池,http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html,http://commons.apache.org/dbcp/configuration.html使用DBCP的连接池可以采用
<Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8"
username="root" password="test" maxActive="500" maxIdle="10"
maxWait="-1" timeBetweenEvictionRunsMillis="10000" minEvictableIdleTimeMillis="10000" />
相关文章推荐
- MySql中的存储过程
- mysql之select(一)
- mysql 5.6.29 绿色版安装
- mysql 5.6.29 绿色版安装
- Mysql常用参数整理
- MySQL基本操作
- MySQL的复制
- MySQL通信协议
- Spark读取数据库(Mysql)的四种方式讲解
- 《Mysql 公司职员学习篇》 第二章 小A的惊喜
- MySQL日志——Undo | Redo
- mysql-5.7.10-winx64 安装
- mysql_5.6.24_winx64 安装
- MySQL存储引擎
- mysql5.7.11解压版安装配置
- MySQL编译安装环境介绍:
- MySQL常用函数
- B、B+树
- mysql联合索引
- mysql慢查询