mysql重连,连接丢失:The last packet successfully received from the server--转载

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增加属性validationQuerytestOnBorrow,如:

<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的时候,添加属性testConnectionOnCheckintestConnectionOnCheckout,如:

<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/

转载于:https://www.cnblogs.com/gengaixue/p/6866564.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/283593.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

.NET MAUI 跨平台应用程序 (Windows App 和 Android )示例

也就前周&#xff0c;.Net MAUI正式版出来了 &#xff0c;一个支持跨平台的UI框架,Linux支持情况官网也没说&#xff0c;按理来说应该也是支持的&#xff0c;刚好&#xff0c;我最近也在研究GUI的基本原理&#xff0c;微软出品还是值得深入研究一下的&#xff0c;就先来个样例&…

OpenStack 计算节点删除

前提 计算节点中一个僵尸计算节点存在&#xff0c;而里面的CPU数目在总物理CPU中&#xff0c;导致认为当前能创建实例。而实际没有这么多资源。其中node-11为僵尸节点。 原因 删除计算节点不能直接格式化该服务器&#xff0c;否则在控制节点的数据库上会存在该计算节点的数据。…

PHP 7.2 新功能介绍

PHP 7.2 已經在 2017 年 11 月 30 日 正式發布 。這次發布包含新特性、功能&#xff0c;及優化&#xff0c;以讓我們寫出更好的代碼。在這篇文章裡&#xff0c;我將會介紹一些 PHP 7.2 最有趣的語言特性。 你可以在 Requests For Comments 頁面查看完整的更動清單。 核心改进 参…

C盘空间不够 mklink解决VScode扩展迁移到其他盘

第一步 将C盘C:\Users\JackieZheng\.vscode文件夹剪切到D:\vscode中去 第二步 以管理员身份运行cmd&#xff0c;执行如下命令&#xff0c;建立符号链接在管理员身份下的cmd中输入如下命令 mklink /D "C:\Users\JackieZheng\.vscode" "D:\vscode\.vscode" 两…

如何打造单文件 Blazor Server 应用

前言上次&#xff0c;我们介绍了《如何打造单文件前后端集成 ASP.NET Core 应用》。但是&#xff0c;网友说&#xff0c;对于 Blazor Server 项目此方法无效。于是&#xff0c;我们测试了一下&#xff1a;BlazorApp1.csproj<Project Sdk"Microsoft.NET.Sdk.Web"&g…

正则化笔记

吉谱斯现象Gibbs&#xff08;又叫吉谱斯效应&#xff09;&#xff1a; 用有限项傅里叶级数表示有间断点的信号时&#xff0c;在间断点附近不可避免的会出现振荡和超量。超量的幅度不会随所取项数的增加而减小。只是随着项数的增多&#xff0c;振荡频率变高&#xff0c;并向间断…

Android线程池详解

引入线程池的好处 1&#xff09;提升性能。创建和消耗对象费时费CPU资源 2&#xff09;防止内存过度消耗。控制活动线程的数量&#xff0c;防止并发线程过多。 我们来看一下线程池的简单的构造 [html] view plaincopy print?public ThreadPoolExecutor(int corePoolSize, …

win11下vscode 自动升级失败 There was an error while marking a file for deletion

当升级vscode时出现下方报错&#xff1a; There was an error while marking a file for deletion:Failed to mark file for deletion:拒绝访问.Please verify there are no Visual Studio Code processes still executing既然是“拒绝访问”应该是权限问题&#xff0c;关闭vsc…

MySQL添加新用户、为用户创建数据库、为新用户分配权限

https://blog.csdn.net/u013216667/article/details/70158452 登录MySQL mysql -u root -p 添加新用户 允许本地 IP 访问 localhost, 127.0.0.1 create user testlocalhost identified by 123456;允许外网 IP 访问 create user test% identified by 123456; 刷新授权 flush p…

【mysql必知必会】第十二章 汇总数据

1、聚集函数&#xff08;aggregate function&#xff09;&#xff1a;运行在行组上&#xff0c;计算和返回单个值得函数。 AVG&#xff08;&#xff09;  返回某列的平均值 COUNT&#xff08;&#xff09;  返回某列的行数 MAX&#xff08;&#xff09;  返回某列的最大值…

盘点大厂的那些开源项目 - 哔哩哔哩

哔哩哔哩现为中国年轻世代高度聚集的文化社区和视频平台&#xff0c;被粉丝们亲切地称为“B站”。overlord分类&#xff1a;缓存服务解决方案开发语言&#xff1a;GOOverlord是哔哩哔哩基于Go语言编写的memcache和redis&cluster的代理及集群管理功能&#xff0c;致力于提供…

单元测试,到底什么是单元测试,为什么单测这么难写

很多小伙伴想知道单测到底该怎么写&#xff0c;于是&#xff0c;文章就来了&#xff01; 话不多说&#xff0c;发车&#xff01; 来源于yes的练级攻略 &#xff0c;作者是Yes呀 到底什么是单元测试 这个问题看似非常简单&#xff0c;单元测试嘛&#xff0c;不就是咱们开发自己…

javascriptjquery 判断滚动到页面底部

js 判断滚动到页面底部 CreateTime--2018年4月14日10:13:07 Author:Marydon 1.使用场景&#xff1a; 滚动到屏幕底部&#xff0c;触发加载分页数据请求&#xff08;qq空间&#xff0c;手机端&#xff09; 2.代码实现 javascript方式 window.onscroll function() {//获取被卷…

Linux 学习和教训

今天在学习Linux的时候&#xff0c;突然脑抽风&#xff0c;在根目录下执行了这样一条命令rm -rf *当时就觉得空气凝固了。。。那时也没有想到可以用数据恢复软件恢复。直接就重启了。重启之后发现&#xff0c;就去就直接是grub>晕菜。。突然间想到可以时候救援模式&#xff…

WinForm(八)窗体,窗体

我们在控件那篇文章里说过&#xff0c;窗体和控件都是一个类&#xff0c;项目中一个个窗体&#xff0c;都是Form类的子类。关于这个类有几个重要的成员&#xff0c;也是最常用成员&#xff0c;以供初学者了解&#xff1a;Load事件&#xff1a;发生在构造函数后&#xff0c;Show…

java8

实验总结 没问题 代码托管 https://git.oschina.net/shuoge/java8 转载于:https://www.cnblogs.com/haha-23333/p/6875325.html

循环、格式化输出、数据统计

主要内容&#xff1a;  for循环 while循环 格式化输出(2) 数据统计及记录 ############################################################# 1、for循环 (A): # #one_guess_age# num_age 40# for i in range(3):# age_input int(input("input age:"))# i…

抓包工具fiddler和wireshark对比

了解过网络安全技术的人都知道一个名词“抓包”。那对于局外人&#xff0c;一定会问什么是抓包&#xff1f;考虑到&#xff0c;大家的技术水平不一&#xff0c;我尽可能用非专业的口吻简单的说一下。 抓包就是将网络传输发送与接收的数据包进行截获、重发、编辑、转存等操作&am…

你被大数据“杀熟”过吗?怎么解决的?丨Q言Q语

点击关注 InfoQ&#xff0c;置顶公众号 接收程序员的技术早餐网友“廖师傅廖师傅”表示&#xff0c;他经常通过某网站订某个特定酒店的房间&#xff0c;长年价格在 380 元 -400 元。偶然一次&#xff0c;他从前台得知酒店淡季的价格在 300 元上下。他用朋友的账号查询也是 300 …

Blazor VS Vue

Vue——两分钟概述Vue 是一个JavaScript 框架。在其最简单的模式中&#xff0c;您可以简单地将核心 Vue 脚本包含在您的应用程序中&#xff0c;然后开始构建您的组件。除此之外&#xff0c;对于更复杂的应用程序&#xff0c;您可以使用 Vue 自己的 CLI 创建&#xff08;并最终发…