`

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.

 

暂时我对我的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:

 

<Resource name="jdbc/saasNetTest" auth="Container" type="javax.sql.DataSource"

               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#socket连接池和连接超时时间设置

    提供一个c# socket连接池设计的例子,解决socket并发连接限制的问题,并且提供一种设置连接超时时间的方法,默认连接超时时间是不能设置的,提供了socket网络发送数据的接口.可用于pos小票打印机通讯。

    PHP访问MySQL查询超时处理的方法

    目前两个客户端扩展库连接超时可以设置选项来操作,比如mysqli: 代码如下: &lt;... //如果超时或者其他连接失败打印错误信息 if (mysqli_connect_errno()) { printf(“Connect failed: %s\n”, mysql

    MySQL_错误代码以及出错信息对照大全

    MySQL_错误代码以及出错信息对照: 0101 属于其他进程的专用标志。 0102 标志已经设置,无法关闭。 0103 无法再次设置该标志。 0104 中断时无法请求专用标志。 0105 此标志先前的所有权已终止。 0106 请...

    解决PHP mysql_query执行超时(Fatal error: Maximum execution time …)

    您可能感兴趣的文章:C#访问SqlServer设置链接超时的方法SQL查询超时的设置方法(关于timeout的处理)Mysql DNS反向解析导致连接超时过程分析(skip-name-resolve)PHP访问MySQL查询超时处理的方法SQL语句执行

    mysql提示got timeout reading communication packets的解决方法

    错误提示: user: ‘root’ host: `localhost’ (Got timeout reading communication packets) MYSQL server has gone away 引起这个原因是不可怕的.原因是更改了系统的断开时间. mysql&gt;show gloable variables ...

    分享一下Mysql常见的几个错误问题及解决方法

    1.问题: mysql DNS反解:skip-name-resolve   错误日志有类似警告: 1.120119 16:26:04 [Warning] IP address ‘192.168.1.10’ could not be resolved: Name or service not known 2.120119 16:26:04 [Warning] ...

    dubbo中zookeeper请求超时问题:mybatis+spring连接mysql8.0.15的配置

    却卡第一个测试上,启动provider服务和Consumer服务,请求接口却始终报zookeeper请求超时错误(dubbo+zookeeper服务端重复调用三次),经过排查,我的问题是出在dao层与数据库连接的问题上(而且provider方还不报错,...

    mysql密码过期导致连接不上mysql

    mysql密码过期了,今天遇到了连接mysql,总是连接不上去, 错误现象1: An attempt by a client to checkout a Connection has timed out 第一次出现连接超时错误,第一反应是去修改cpool.checkoutTimeout参数为...

    解决MYSQL连接端口被占引入文件路径错误的问题

    随后又下载了相关2.4,2.5等相关版本安装,依旧没有解决,主要现象是mysql命令符中输入密码回车之后没有反应,随后命令符自动消失,另外就是在PHPMyAdmin中输入密码直接出现连接超时等的三条错误提示,或者是提示...

    mysql数据库my.cnf配置文件

    # MySQL的最大连接数,如果服务器的并发连接请求量比较大,建议调高此值,以增加并行连接数量,当然这建立在机器能支撑的情况下,因为如果连接数越多,介于MySQL会为每个连接提供连接缓冲区,就会开销越多的内存,...

    通过DBLINK查询出现的问题

    NULL 博文链接:https://czwlucky.iteye.com/blog/964093

    IDEA配置连接MYSQL数据库遇到Failed这个问题解决

    本文主要介绍了IDEA配置连接MYSQL数据库遇到Failed这个问题解决,分享给大家,具体如下:   错误位置如下 我们改过来 发现就能正常连接 IDEA尝试连接Mysql时失败 在尝试用IDEA连接的Mysql时一直显示连接失败,...

    MySQL MTOP v2.1.zip

    MySQL MTOP是一个由Python PHP开发的开源MySQL企业监控系统。...MySQL服务器无需安装任何Agent,只需在监控WEB界面配置相关...4.管理中心退出链接地址错误 5.修复内核信息与HOSTNAME不对应问题,更改HOSTNAME为中文主机名

    MySQL管理之道 性能调优、高可用与监控.part2.rar

    《mysql管理之道:性能调优、高可用与监控》由资深mysql专家撰写,以最新的mysql版本为基础,以构建高性能mysql服务器为核心,从故障诊断、表设计、sql优化、性能参数调优、mydumper逻辑、xtrabackup热备份与恢复、...

    PHP和MySQL Web开发第4版pdf以及源码

    1.5.2 字符串的连接 1.5.3 变量和文本 1.6 理解标识符 1.7 检查变量类型 1.7.1 PHP的数据类型 1.7.2 类型强度 1.7.3 类型转换 1.7.4 可变变量 1.8 声明和使用常量 1.9 理解变量的作用域 1.10 使用操作符 ...

    基于MySQL的数据库中间件Meituan-DBProxy.zip

    增加后台MySQL版本号设置,主要影响MySQL连接协议中的server版本,客户端驱动可能依赖于server版本处理机制有所不同。由参数mysql-version控制 性能改进,将SQL词法分析从串行方式改进为并发方式;其次,...

    PHP和MySQL WEB开发(第4版)

    20.5.3 避免超时 20.5.4 使用其他的FTP函数 20.6 进一步学习 20.7 下一章 第21章 日期和时间的管理 21.1 在PHP中获取日期和时间 21.1.1 使用date()函数 21.1.2 使用UNIX时间戳 21.1.3 使用getdate()函数 21.1.4 ...

    MYSQL无法连接 提示10055错误的解决方法

    1、IIS网站服务器中各个网站中有“连接超时时间”,“会话超时时间”; 2、其它程序占用的服务器连接数(如SMTP服务在发信出去的时候可能有很多个连接数) 3、服务器本身的TCP/IP连接数,如xp系统就有个限制,不过...

    MySQL server has gone away错误提示解决方法

    还有一种可能是因为某些原因导致超时,比如说程序中获取数据库连接时采用了Singleton的做法,虽然多次连接数据库,但其实使用的都是同一个连接,而且程序中某两次操作数据库的间隔时间超过了wait_timeout(SHOW ...

    transaction_retry:重试有关死锁和事务序列化错误的数据库事务。 支持MySQL,PostgreSQL和SQLite

    transaction_retry 重试有关死锁和事务序列化错误的数据库事务。 支持MySQL,PostgreSQL和...连接到数据库后。 重试的数据库死锁和序列化错误 MySQL 尝试获取锁时发现死锁 超过锁定等待超时 PostgreSQL 检测到死锁

Global site tag (gtag.js) - Google Analytics