首页 / MYSQL / mysql连接超时异常
mysql连接超时异常
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql连接超时异常,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3712字,纯文字阅读大概需要6分钟。
内容图文
![mysql连接超时异常](/upload/InfoBanner/zyjiaocheng/558/26366a32ef9e45ac816273d12ac12710.jpg)
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.
暂时我对我的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
?
内容总结
以上是互联网集市为您收集整理的mysql连接超时异常全部内容,希望文章能够帮你解决mysql连接超时异常所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。