0

0

mysql 连接超时异常

php中文网

php中文网

发布时间:2016-06-07 16:23:47

|

1654人浏览过

|

来源于php中文网

原创

mysql 连接超时错误 自己的小网站在测试机器上长时间不访问后(默认8小时过期),再次访问发现有如下错误: Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received fro m the server was 63,020,509 m

mysql 连接超时错误

自己的小网站在测试机器上长时间不访问后(默认8小时过期),再次访问发现有如下错误:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received fro

m the server was 63,020,509 milliseconds ago. ?The last packet sent successfully to the server was 63,020,509

?milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either e

xpiring and/or testing connection validity before use in your application, increasing the server configured v

alues for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this pr

oblem.

? ? ? ? at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

? ? ? ? at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

? ? ? ? at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:4

5)

? ? ? ? at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

? ? ? ? at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)

? ? ? ? at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)

? ? ? ? at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3851)

? ? ? ? at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)

? ? ? ? at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)

? ? ? ? at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683)

? ? ? ? at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144)

? ? ? ? at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)

? ? ? ? at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)

? ? ? ? at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)

?

Fix:?If only the connection pool could check if the the connection it is about to return is live or not, the porblem is fixed. This can be done in apache-common-dbcp (I know this one coz I used it, please look into documentation of the connection-pool you are using). Here’s how you do it: You add the following properties to dbcp configuration.

  • validationQuery=”SELECT 1″
  • testOnBorrow=”true”

And that does the trick.

Difeye-敏捷的轻量级PHP框架
Difeye-敏捷的轻量级PHP框架

Difeye是一款超轻量级PHP框架,主要特点有: Difeye是一款超轻量级PHP框架,主要特点有: ◆数据库连接做自动主从读写分离配置,适合单机和分布式站点部署; ◆支持Smarty模板机制,可灵活配置第三方缓存组件; ◆完全分离页面和动作,仿C#页面加载自动执行Page_Load入口函数; ◆支持mysql,mongodb等第三方数据库模块,支持读写分离,分布式部署; ◆增加后台管理开发示例

下载

?

暂时我对我的mysql连接加上: 试试效果

validationQuery="SELECT 1"

?testOnBorrow="true"

?

目前我不想添加: ?autoReconnect=true? 因为我对此的理解不深,mysql文档这样写的:

?

This parameter is?false?by default. This forces disconnected API nodes (including MySQL Servers acting as SQL nodes) to use a new connection to the cluster rather than attempting to re-use an existing one, as re-use of connections can cause problems when using dynamically-allocated node IDs. (Bug #45921)

如果有问题再添加 autoReconnect选项

like this:

?

? ? ? ? ? ? ? ?initialSize="10" maxActive="100" maxIdle="30" maxWait="10000"

? ? ? ? ? ? ? ?username="***" password="***" driverClassName="com.mysql.jdbc.Driver"

? ? ? ? ? ? ? ?url="jdbc:mysql://localhost:3306/saasNetTest"

? ? ? ? ? ? ? ?validationQuery="SELECT 1"

? ? ? ? ? ? ? ?testOnBorrow="true"

?

? ? />

?

参考文档:http://stackoverflow.com/questions/9674165/mysql-jdbc-timeout-even-with-autoreconnect-true

http://amitcodes.com/2008/07/26/16/

http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency

?

相关专题

更多
c++主流开发框架汇总
c++主流开发框架汇总

本专题整合了c++开发框架推荐,阅读专题下面的文章了解更多详细内容。

97

2026.01.09

c++框架学习教程汇总
c++框架学习教程汇总

本专题整合了c++框架学习教程汇总,阅读专题下面的文章了解更多详细内容。

50

2026.01.09

学python好用的网站推荐
学python好用的网站推荐

本专题整合了python学习教程汇总,阅读专题下面的文章了解更多详细内容。

139

2026.01.09

学python网站汇总
学python网站汇总

本专题整合了学python网站汇总,阅读专题下面的文章了解更多详细内容。

12

2026.01.09

python学习网站
python学习网站

本专题整合了python学习相关推荐汇总,阅读专题下面的文章了解更多详细内容。

19

2026.01.09

俄罗斯手机浏览器地址汇总
俄罗斯手机浏览器地址汇总

汇总俄罗斯Yandex手机浏览器官方网址入口,涵盖国际版与俄语版,适配移动端访问,一键直达搜索、地图、新闻等核心服务。

81

2026.01.09

漫蛙稳定版地址大全
漫蛙稳定版地址大全

漫蛙稳定版地址大全汇总最新可用入口,包含漫蛙manwa漫画防走失官网链接,确保用户随时畅读海量正版漫画资源,建议收藏备用,避免因域名变动无法访问。

431

2026.01.09

php学习网站大全
php学习网站大全

精选多个优质PHP入门学习网站,涵盖教程、实战与文档,适合零基础到进阶开发者,助你高效掌握PHP编程。

49

2026.01.09

php网站搭建教程大全
php网站搭建教程大全

本合集专为零基础用户打造,涵盖PHP网站搭建全流程,从环境配置到实战开发,免费、易懂、系统化,助你快速入门建站!

13

2026.01.09

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
MySQL 教程
MySQL 教程

共48课时 | 1.7万人学习

MySQL 初学入门(mosh老师)
MySQL 初学入门(mosh老师)

共3课时 | 0.3万人学习

简单聊聊mysql8与网络通信
简单聊聊mysql8与网络通信

共1课时 | 785人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号