- 浏览: 634199 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (820)
- java开发 (110)
- 数据库 (56)
- javascript (30)
- 生活、哲理 (17)
- jquery (36)
- 杂谈 (15)
- linux (62)
- spring (52)
- kafka (11)
- http协议 (22)
- 架构 (18)
- ZooKeeper (18)
- eclipse (13)
- ngork (2)
- dubbo框架 (6)
- Mybatis (10)
- 缓存 (28)
- maven (20)
- MongoDB (3)
- 设计模式 (3)
- shiro (10)
- taokeeper (1)
- 锁和多线程 (3)
- Tomcat7集群 (12)
- Nginx (34)
- nodejs (1)
- MDC (1)
- Netty (7)
- solr (15)
- JSON (8)
- rabbitmq (32)
- disconf (7)
- PowerDesigne (0)
- Spring Boot (31)
- 日志系统 (6)
- erlang (2)
- Swagger (3)
- 测试工具 (3)
- docker (17)
- ELK (2)
- TCC分布式事务 (2)
- marathon (12)
- phpMyAdmin (12)
- git (3)
- Atomix (1)
- Calico (1)
- Lua (7)
- 泛解析 (2)
- OpenResty (2)
- spring mvc (19)
- 前端 (3)
- spring cloud (15)
- Netflix (1)
- zipkin (3)
- JVM 内存模型 (5)
- websocket (1)
- Eureka (4)
- apollo (2)
- idea (2)
- go (1)
- 业务 (0)
- idea开发工具 (1)
最新评论
-
sichunli_030:
对于频繁调用的话,建议采用连接池机制
配置TOMCAT及httpClient的keepalive以高效利用长连接 -
11想念99不见:
你好,我看不太懂。假如我的项目中会频繁调用rest接口,是要用 ...
配置TOMCAT及httpClient的keepalive以高效利用长连接
Mysql服务器默认的“wait_timeout”是8小时【也就是默认的值默认是28800秒】,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection,通俗的讲就是一个连接在8小时内没有活动,就会自动断开该连接。 wait timeout的值可以设定,但最多只能是2147483,不能再大了。也就是约24.85天 所以即使你MySQL通过my.ini 在 # The TCP/IP Port the MySQL Server will listen on port=3306下面添加 # this is myown dinifition for mysql connection timeout wait_timeout=31536000 interactive_timeout=31536000 无论超过最大限度多大的数值,只能被MySQL解析为2147483,2147483天后你的程序该出什么错还是什么错,避免不了的
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>
参考
MySQL reconnect issues
附录分析
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://sourceforge.net/p/c3p0/mailman/message/18310863/
mysql重连,连接丢失:The last packet successfully received from the server--转载
http://www.cnblogs.com/davidwang456/p/4425913.html
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>
参考
MySQL reconnect issues
附录分析
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://sourceforge.net/p/c3p0/mailman/message/18310863/
mysql重连,连接丢失:The last packet successfully received from the server--转载
http://www.cnblogs.com/davidwang456/p/4425913.html
发表评论
-
mysql列转行函数GROUP_CONCAT
2024-12-23 19:42 10mysql列转行函数是什么 GROUP_CONCAT(expr ... -
mysql字段限定在某一范围取值
2023-12-15 15:02 385mysql字段限定在某一范围取值 -
mysql查询动态行转动态列,并使用mybatis执行
2023-04-02 22:56 694mysql查询动态行转动态列,并使用mybatis执行 My ... -
MySQL 正则表达式 通过正则匹配字符、替换特定字符、返回特定字符
2022-12-29 14:54 393MySQL 正则表达式 通过正则匹配字符、替换特定字符、返回特 ... -
MySQL InnoDB update锁表问题Record Locks
2022-12-20 12:26 296MySQL InnoDB update锁表问题Record L ... -
oracle 使用flashback(闪回)恢复误删除的数据 或 误删除的表
2022-09-02 19:44 289oracle 使用flashback(闪回)恢复误删除的数据 ... -
数据库面试题
2022-04-06 21:48 229分布式事务解决方案之TCC 分布式事务解决方案——Seata ... -
面试题
2022-02-11 11:38 263Java面试题目大汇总 数据库事务的隔离级别从低到高的顺序依 ... -
mysql相关问题 WAL机制、crash safe如何实现、redo log作用
2019-07-16 23:43 577https://www.jianshu.com/p/cd914 ... -
MySQL -- 内存使用监控详解
2019-06-12 13:59 661第一步: 配置performance_schema使它开启内存 ... -
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregate
2018-01-01 12:17 1279https://www.cnblogs.com/lonelyw ... -
MySQL使用profile分析SQL执行状态
2017-08-24 09:49 553http://blog.csdn.net/staricqxyz ... -
blocked because of many connection errors; unblock with 'mysqladmin flush-hosts
2017-06-21 16:56 672错误:Host is blocked becaus ... -
MySQL半同步复制配置
2017-05-08 14:14 756MySQL半同步复制配置 http://blog.csdn.n ... -
mysql.sock的作用
2017-04-18 11:29 513Mysql有两种连接方式: (1),TCP/IP ... -
Linux下源码安装MySQL 5.6
2017-04-16 20:30 647http://blog.sina.com.cn/s/blog_ ... -
docker中mysql初始化及启动失败解决办法
2017-04-12 20:56 1843http://blog.csdn.net/rznice/art ... -
MySQL数据库自动生成并修改随机root密码的脚本
2017-03-25 15:10 1034http://blog.csdn.net/yumushui/a ... -
centos6.5下yum安装mysql5.5和php5.6
2017-03-22 14:34 549http://www.cnblogs.com/SQL888/p ... -
Linux平台卸载MySQL和PHP
2017-03-22 13:58 411http://www.cnblogs.com/kerrycod ...
相关推荐
解决连接超时问题需要从多方面考虑,包括调整 wait_timeout 参数的值、使用 Connector/J 连接属性、及时释放连接等方法。只有通过合适的方法,才能避免连接超时问题的出现,提高系统性能和稳定性。
MySQL 连接超时问题是常见的错误之一,解决该问题需要了解 wait_timeout 参数的重要性,并正确地使用 show variables 命令。同时,在使用 Hibernate 框架进行数据库操作时,需要注意连接超时问题,并采取相应的解决...
MySQL的`wait_timeout`连接超时问题通常出现在长时间无操作的数据库连接上,服务器会自动关闭这些连接以释放资源。这种现象在应用中可能导致突然的数据通信中断,表现为“Communications link failure”等错误,提示...
总之,MySQL的连接超时问题主要是由`wait_timeout`参数引发的,解决方法包括但不限于调整MySQL服务器配置、使用连接池、更新应用程序代码以处理连接失效的情况,以及在使用ORM框架时,按照框架的文档配置相应的连接...
在MySQL中,`interactive_timeout` 和 `wait_timeout` 是两个重要的配置参数,它们与客户端连接到服务器的超时设置紧密相关。理解这两个参数的区别对于优化数据库性能和避免不必要的连接断开至关重要。 `...
错误提示: user: ‘root’ host: `localhost’ (Got timeout reading communication ...wait_timeout 的默认值这:120 根据情况增加吧. 这两个值是一个全局变量,可以动态增加,如: mysql> set global interactiv
需要注意的是,尽管调整`interactive_timeout`可以解决连接超时问题,但过度增加超时时间可能会导致服务器资源被长时间占用,尤其是在高并发的环境中。因此,优化数据库连接管理和使用连接池是更推荐的做法。 连接...
在MySQL数据库操作中,"SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded" 是一个常见的错误,它意味着在执行事务时,系统等待锁定资源的时间超过了预设的限制。这个错误通常发生在并发环境中,当...
- `SET GLOBAL wait_timeout=120`:设置非交互式连接的超时时间,单位为秒。如果超过这个时间没有活动,连接将被自动断开。 - `SET GLOBAL interactive_timeout=300`:设置交互式连接的超时时间。与`wait_timeout`...
然而,为了优化资源使用,MySQL配置了一个参数`wait_timeout`,这个参数定义了连接在空闲多长时间后会被自动关闭。当JavaEE应用中的数据库连接在超过这个设定的时间没有执行任何操作,MySQL服务器会断开这个连接,这...
2. **wait_timeout** 和 **interactive_timeout**: 这两个参数分别定义了非交互式连接和交互式连接在无活动状态后等待多久关闭。在上述例子中,它们都被设置为2880000秒(约80小时)。这有助于防止长时间运行的还原...
通过对`connect_timeout`、`interactive_timeout`、`wait_timeout`等参数的调整,可以更好地控制连接的生命周期,防止因长时间无响应导致的问题,并确保系统能够有效地处理各种查询。在进行调整时,务必根据实际情况...
`wait_timeout`和`interactive_timeout`则是关于连接空闲时的超时设置。`wait_timeout`用于非交互式连接,即不进行任何查询操作的连接,如果在指定时间内没有活动,服务器将自动关闭连接。而`interactive_timeout`是...
mysql5将其连接的等待时间(wait_timeout)缺省为8小时。怎么不让它超时呢
Spring Boot 解决 Mysql ...解决 Spring Boot 连接 Mysql 断连问题可以使用多种方法,包括在 application.properties 文件中添加配置项、修改 Mysql 的 wait_timeout 参数等。选择合适的方法可以根据实际情况进行选择。