mysql 连接丢失错误解决(转载)
1.1 错误信息:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 20,820,001 milliseconds ago. The last packet sent successfully to the server was 20,820,002 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.
at sun.reflect.GeneratedConstructorAccessor29.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_51]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_51]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1129) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3988) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2598) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2828) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:5372) ~[mysql-connector-java-5.1.29.jar:na]
at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:881) ~[c3p0-0.9.1.1.jar:0.9.1.1]
at org.quartz.impl.jdbcjobstore.AttributeRestoringConnectionInvocationHandler.setAutoCommit(AttributeRestoringConnectionInvocationHandler.java:98) ~[quartz-2.2.1.jar:na]
1.2 解决方法
- 如果使用的是JDBC,在JDBC URL上添加?autoReconnect=true
,如:
jdbc:mysql://10.10.10.10:3306/mydb?autoReconnect=true
- 如果是在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>
- 如果是在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>
参考
附录分析
When a c3p0-proxied Connection throws an SQLException, c3p0 examines
the Exception and the Connection to make a judgement about whether
the problem implies that the Connection should no longer be included
in the pool. c3p0 tests the Connection, and if the test fails, the
Connection will be excluded from the pool. What c3p0 is telling you here is that a Connection that previously
signalled an error and then failed a Connection test is still in use,
and has signalled another error. From c3p0's perspective, this is a
non-issue, it just means c3p0 doesn't have to do any kind of checks
or notifications, the Connection is already gone as far as the pool
is concerned. But c3p0 wonders why you'd still be using such a
Connection, and warns you about it. Usually, if a client continues to use a Connection that c3p0 has
correctly identified as broken, all further uses will provoke such an
exception, and the fix is to close the Connection and start over when
an application's Connection turns out to be dead. But, by the error
you're getting, it looks like your Connection is still live and okay
-- it's clearly communicating with the database. So, the issue is,
why did c3p0 deem the Connection dead if it is not? If you turn on DEBUG level logging (relevant loggers would be
com.mchange.v2.c3p0.impl.NewPooledConnection,
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool, and
com.mchange.v2.c3p0.impl.DefaultConnectionTester, unless you've
defined your own ConnectionTester), you can trace the testing and
invalidation of Connections, and try to understand why Connections
that seem okay are testing as broken. That will give you better
information about what's going on. That said, the only cost of this behavior is disconcerting warning
messages and somewhat faster churn of Connections through the pool.
c3p0 is erring on the side of caution -- it has reason to believe a
Connection is bad, so it's been excluded from the pool. It'd be nice
to know why apparently good Connections are failing Connection tests,
but if it is an infrequent occurrence, it's very little to worry
about. (If it's happening a lot, you should track it down.) 原文地址:http://www.cnblogs.com/davidwang456/p/4425913.html
mysql 连接丢失错误解决(转载)的更多相关文章
- Linux 下一个 Mysql error 2002 错误解决
Linux 下一个 Mysql error 2002 错误解决 首先查看 /etc/rc.d/init.d/mysqld status 查看mysql它已开始. 假设启动的的话,先将数 ...
- pycharm中连接MySql出现 Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.的错误解决
具体异常如下: 这个异常特别烦人,是mysql连接驱动的问题,可以用二步解决: 第一步 从网上下载驱动,从mysql-connector-java_8.0.16-1ubuntu16.04_all.de ...
- mysql远程连接以及错误解决&命令行基本操作
现在大家的程序服务基本都是部署在云服务器上,今天我分享记录一下:使用mysql数据库过程中比较常见操作和遇到的问题 环境:lunix 系统(阿里云服务器,华为云服务器,腾讯云等均适用) + mysql ...
- IntelliJ IDEA web项目进行数据库连接时出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误解决办法
首先看报错信息: 意思是找不到类: com.mysql.jdbc.Driver.也就是说tomcat找不到MySQL数据库连接要用的jar包! 出现这种错误的原因是: 项目中没有导入这个jar包, ...
- mysql安装及错误解决
#下载mysql源安装包shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm# 安装my ...
- Zookeeper 报ConnectionLostException连接丢失错误汇总
我google出来的几个结果都没有用,这里写出来或许可以帮助别人,这些都是google出来的结果,没有经过验证是否真的能够解决问题. 当前zookeeper的连接状态是connecting,这个时候连 ...
- mysql服务器无法连接10055错误解决示例
windows服务器下,mysql运行一段时间之后忽然无法连接,但是mysql服务启动正常,连接时报错: can't connect to mysql server on 'localhost ...
- 使用sqlyog或者navicat连接mysql提示1862错误解决
mysql的bin目录下执行 mysqladmin -uroot -p password 依次输入旧密码.新密码.确认新密码 修改后重新使用sqlyog或navicat连接成功 问题解决!
- Digao 连接Mysql 连接不上解决办法
错误一:No module named 'MySQLdb' 原因:python3连接MySQL不能再使用mysqldb,取而代之的是pymysql. 解决方法:在python的MySQL包中,即路径: ...
随机推荐
- [改善Java代码]使用匿名类的构造函数
建议39: 使用匿名类的构造函数 阅读如下代码,看看是否可以编译: public class Client { public static void main(String[] args) { Lis ...
- 多tab页框架的使用场合
多tab页框架适合应用于功能较少的场合,例如邮箱后台之类的. 对于一些业务功能多且复杂的场合就不适用.打开过多的tab页容易给用户造成混乱,页面的跳转也存在一定的难度. 一种新技术不能完全取代旧技术, ...
- 看linux连接进程占用的实时流量iftop netatop NetHogs
因为新工厂的机器上面的业务混合部署非常严重,加上内网外网共用一个网卡(这个更不可思议),导致有时要定位一些进程流量的问题非常困难,所以最近花了点时间在网上搜集了一把 (aptitude search ...
- CSS3秘笈第三版涵盖HTML5学习笔记13~17章
第13章,构建基于浮动的布局 使用的是float(浮动)属性 注:float:none值将取消所有浮动,通常只用来取消元素中已经应用的浮动. 切记:不需要给正文的div设计宽度,即使设计成固定宽度也不 ...
- Linux 命令 - ftp: 网络文件传输工具
命令格式 ftp [-pinegvd] [host] 命令参数 -A 传输文件模式为主动模式. -p 传输文件模式为被动模式. -i 关闭交互模式. -n 关闭自动登录功能. -e 不记录历史命令. ...
- HTML5新特性之WebNotifications
Web Notifications是HTML5中一个令人欣喜的新特性,它支持开发者配置和显示桌面通知,为用户提供更好的体验,最令人称赞的是,即使用户忙于其他工作时也可以收到来自页面的消息通知,例如一个 ...
- ios swift reduce Method
Swift’s API includes many functions and instance methods that reflect its functional programming her ...
- Cocos2d-x如何控制动作速度
基本动作和组合动作实现了针对精灵的各种运动和动画效果的改变.但这样的改变速度匀速的.线性的.通过ActionEase及其的派生类和Speed 类我们可以使精灵以非匀速或非线性速度运动,这样看起了效果更 ...
- 关于web请求中 获取真实IP
HttpRequest request = HttpContext.Current.Request; if (!string.IsNullOrEmpty(request.ServerVariables ...
- 慕课网上的Bootstrap学习(二)
表单 首先<form role="form" class="form-horizontal"></form> ,创建一个水平显示的表单. ...