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,如:

- 如果是在Spring中使用c3p0连接池,则在定义datasource的时候,添加属性testConnectionOnCheckin和testConnectionOnCheckout,如:

参考

附录分析

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.)

mysql链接丢失_mysql 连接丢失错误解决(转载)相关推荐

  1. 连接mysql报2059错_MySQL连接2059错误解决方法

    开始学MySQL,结果安装完SQLyog后连接不了,总是弹出提示2059错误.在网上查找了一下才发现原因,MySQL8.0.11版本启用了新特性,用户登录加密规则改为了caching_sha2_pas ...

  2. mysql 链接慢_mysql连接非常慢的觖决办法及其它常见问题解决办法

    在服务器上部署了一个php网站,但速度慢得让人无法忍受,一开始还以为是php的原因,后来发现是与数据库交互太慢,慢得离谱,在网上找到一个解决办法: 编辑/etc/my.cnf 在[mysqld]段中加 ...

  3. Mysql连接1045错误解决

    MySql连接1045 错误 解决方法 一.停止MySql服务 修改my.ini文件 在[mysqld]关键字下添加skip-grant-tables字段并保存 skip-grant-tables 启 ...

  4. mysql 增删改查时的错误解决方法大全

    mysql 增删改查时的错误解决方法大全     信息1:Error: Access denied for user: 'linanma@localhost' (Using password: YES ...

  5. ORCAL数据库远程连接是报:12170连接超时错误解决办法

    ORCAL数据库远程连接是报:12170连接超时错误解决办法 问题: 今天在进行数据库连接时发现报了12170错误,通过查找资料原来是服务器防火墙的问题 解决方法: 因为我是把数据库部署到虚拟机上的, ...

  6. win10系统下安装Navicat for MySql 连接出现错误解决方法

    在安装Navicat for Mysql完成后,连接时出现"1045-Acess denied for user:'root'@'localhost'(Using password:YES) ...

  7. mysql navicat授权_Mysql授权允许远程访问解决Navicat for MySQL连接mysql提示客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端...

    Navicat Premium连接MySQL 1251错误 MySQL Installer 8.0.17 ​ 出现上述错误的原因是版本MySQL 8.0.17即8.0开始的MySQL版本,因为采用新的 ...

  8. mysql 数据精确度_mysql数据精度丢失问题深入探讨

    不要盲目的说float和double精度可能发生丢失,而是说在存取时因为精度不一致会发生丢失,当然这里的丢失指的是扩展或者截断了,丢失了原有的精度.decimal是好,但不是说不会发生任何精度丢失.如 ...

  9. mysql 1236_Mysql主从同步Last_IO_Errno:1236错误解决方法

    Mysql主从同步的Last_IO_Errno:1236错误是什么原因呢,我们要如何来解决这个问题呢?下面和小编一起来看看关于此问题的记录与解决办法. 从服务器错误代码: Last_IO_Errno: ...

最新文章

  1. 函数式思维: 利用 Either 和 Option 进行函数式错误处理 类型安全的函数式异常...
  2. 计时器StopWatch示例
  3. HDU 2035.人见人爱A^B-快速幂
  4. java python算法_用Java,Python和C ++示例解释的搜索算法
  5. 企业战略咨询方法:学习SWOT分析
  6. oss/bss/mss转自搜搜百科
  7. spark broadcast的TorrentBroadcast实现
  8. 谷歌发布MetNet神经网络模型预测天气
  9. jQuery操作动画队列
  10. 可编译的java代码_有没有编译方法可以运行Java代码?
  11. 【语谱图】基于matlab语音信号语谱图【含Matlab源码 137期】
  12. Javascript培训PPT
  13. 第三方系统平台如何对接gooflow2.0
  14. foobar 2000 介绍
  15. Wpf 初学---01设计一个优美的注册界面
  16. 前端性能优化的关键时间点
  17. 微信小程序在线知识答题有奖多开版源码
  18. Opencv去除高光
  19. 基于MatLab实现LSB(最低有效位)算法完成图片数字水印隐写功能
  20. 【转载】Python遍历pandas数据方法总结

热门文章

  1. MongoDB工具介绍
  2. 输入一颗二元树,从上向下按层打印树的每个节点,同一层中,按照从左到右的顺序打印。...
  3. Android 编辑中的快捷键
  4. C++ vector容器类型 (转)
  5. 微信小程序按钮Button使用详解
  6. Springboot02配制jsp
  7. Mr.J-- jQuery学习笔记(十六)--展开和收起动画折叠菜单的实现
  8. 02 ansible核心模块 之 shell script
  9. Shape Number (最小表示法)
  10. [PHP] - 逗号和点号的区别