今天部署项目上线 然后sql查询失败,看日志发现

The last packet successfully received from the server was 607,486 milliseconds ago. The last packet sent successfully to the server was 3,980,005 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.

提示你修改参数什么的(不要用),这个方法很不好

修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:

[mysqld]

wait_timeout=31536000

interactive_timeout=31536000

重启生效,需要同时修改这两个参数。

然后我的连接池是c3p0,遇到这个问题的伙伴可以根据不同的数据连接池去找你们的相关配置。

c3p0修改解决这个问题:

1、数据库执行命令:

show global variables like '%timeout%';

查看你的数据库的wait_timeout时间

然后根据你的时间去设置<property name="idleConnectionTestPeriod"><value>3</value></property> 的值,如果是30 那value就小于30,10的话就小于10,必须是小于!

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"    destroy-method="close">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/><property name="minPoolSize"><value>1</value></property><property name="maxPoolSize"><value>20</value></property><property name="maxIdleTime"><value>1800</value></property><property name="acquireIncrement"><value>2</value></property><property name="maxStatements"><value>0</value></property><property name="initialPoolSize"><value>2</value></property><property name="idleConnectionTestPeriod"><value>3</value></property><property name="breakAfterAcquireFailure"><value>true</value></property>
</bean>

然后在贴出c3p0各个配置详解!

参考:C3P0使用详解 - 滥好人 - 博客园

<c3p0-config>    <default-config>    <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->    <property name="acquireIncrement">3</property>    <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->    <property name="acquireRetryAttempts">30</property>    <!--两次连接中间隔时间,单位毫秒。Default: 1000 -->    <property name="acquireRetryDelay">1000</property>    <!--连接关闭时默认将所有未提交的操作回滚。Default: false -->    <property name="autoCommitOnClose">false</property>    <!--c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么    属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试    使用。Default: null-->    <property name="automaticTestTable">Test</property>    <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效    保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试    获取连接失败后该数据源将申明已断开并永久关闭。Default: false-->    <property name="breakAfterAcquireFailure">false</property>    <!--当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出    SQLException,如设为0则无限期等待。单位毫秒。Default: 0 -->    <property name="checkoutTimeout">100</property>    <!--通过实现ConnectionTester或QueryConnectionTester的类来测试连接。类名需制定全路径。    Default: com.mchange.v2.c3p0.impl.DefaultConnectionTester-->    <property name="connectionTesterClassName"></property>    <!--指定c3p0 libraries的路径,如果(通常都是这样)在本地即可获得那么无需设置,默认null即可    Default: null-->    <property name="factoryClassLocation">null</property>    <!--Strongly disrecommended. Setting this to true may lead to subtle and bizarre bugs.    (文档原文)作者强烈建议不使用的一个属性-->    <property name="forceIgnoreUnresolvedTransactions">false</property>    <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->    <property name="idleConnectionTestPeriod">60</property>    <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->    <property name="initialPoolSize">3</property>    <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->    <property name="maxIdleTime">60</property>    <!--连接池中保留的最大连接数。Default: 15 -->    <property name="maxPoolSize">15</property>    <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements    属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。    如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->    <property name="maxStatements">100</property>    <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->    <property name="maxStatementsPerConnection"></property>    <!--c3p0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能    通过多线程实现多个操作同时被执行。Default: 3-->    <property name="numHelperThreads">3</property>    <!--当用户调用getConnection()时使root用户成为去获取连接的用户。主要用于连接池连接非c3p0    的数据源时。Default: null-->    <property name="overrideDefaultUser">root</property>    <!--与overrideDefaultUser参数对应使用的一个参数。Default: null-->    <property name="overrideDefaultPassword">password</property>    <!--密码。Default: null-->    <property name="password"></property>    <!--定义所有连接测试都执行的测试语句。在使用连接测试的情况下这个一显著提高测试速度。注意:    测试的表必须在初始数据源的时候就存在。Default: null-->    <property name="preferredTestQuery">select id from test where id=1</property>    <!--用户修改系统配置参数执行前最多等待300秒。Default: 300 -->    <property name="propertyCycle">300</property>    <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的    时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable    等方法来提升连接测试的性能。Default: false -->    <property name="testConnectionOnCheckout">false</property>    <!--如果设为true那么在取得连接的同时将校验连接的有效性。Default: false -->    <property name="testConnectionOnCheckin">true</property>    <!--用户名。Default: null-->    <property name="user">root</property>    <!--早期的c3p0版本对JDBC接口采用动态反射代理。在早期版本用途广泛的情况下这个参数    允许用户恢复到动态反射代理以解决不稳定的故障。最新的非反射代理更快并且已经开始    广泛的被使用,所以这个参数未必有用。现在原先的动态反射与新的非反射代理同时受到    支持,但今后可能的版本可能不支持动态反射代理。Default: false-->    <property name="usesTraditionalReflectiveProxies">false</property>  <property name="automaticTestTable">con_test</property>    <property name="checkoutTimeout">30000</property>    <property name="idleConnectionTestPeriod">30</property>    <property name="initialPoolSize">10</property>    <property name="maxIdleTime">30</property>    <property name="maxPoolSize">25</property>    <property name="minPoolSize">10</property>    <property name="maxStatements">0</property>    <user-overrides user="swaldman">    </user-overrides>    </default-config>    <named-config name="dumbTestConfig">    <property name="maxStatements">200</property>    <user-overrides user="poop">    <property name="maxStatements">300</property>    </user-overrides>    </named-config>
</c3p0-config>

完毕

PS:如何确定c3p0 max_statements

参考:mysql-如何确定c3p0 max_statements - CocoaChina_一站式开发者成长社区

对于maxPoolSize 50池来说,hibernate.c3p0.max_statements的值太小.即使在解决了死锁问题之后,通过语句进行搅动也将减少或消除语句高速缓存的任何性能优势.要为hibernate.c3p0.max_statements(映射到c3p0.maxStatements)计算一个好的值,计算应用程序中经常使用的不同PreparedStatement的数量,然后将其乘以maxPoolSize(或者在您的情况下为hibernate.c3p0.max_size).或者,只需将hibernate.c3p0.maxStatementsPerConnection设置为应用程序经常使用的不同PreparedStatements的数量.

日志输出The last packet successfully received问题以及c3p0解决方案,max_statements相关推荐

  1. mysql报错last packet_mysql The last packet successfully received

    mysql服务器最近老是报错,内容如下: The last packet successfully received from the server was 65,502,275 millisecon ...

  2. The last packet successfully received from the server was 1,547,682,071 milliseconds ago. The last

    MySQL 经常出现这样的错误: org.springframework.dao.DataAccessResourceFailureException:   PreparedStatementCall ...

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

    原文地址:http://nkcoder.github.io/blog/20140712/mysql-reconnect-packet-lost/ 1.1 错误信息: Caused by: com.my ...

  4. Communications link failure,The last packet successfully received from the serve

    最近做测试,发现Mysql 过一段时间会无法连接,导致数据库数据不一至,极其郁闷. 使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: Communications l ...

  5. The last packet successfully received from the server was 39,900 milliseconds ago问题解决

    The last packet successfully received from the server was 39,900 milliseconds ago问题解决 参考文章: (1)The l ...

  6. The last packet successfully received from the server was 1,072 milliseconds ago. The last packet s

    问题: 今天在运行一个打包好的 jar 项目的时候,报了标题上的这个错误. 具体错误如下: 2022-05-06 16:42:23.534 [main] INFO com.zer.MyApplicat ...

  7. The last packet successfully received from the server was 3,607 milliseconds ago. The last packet s

    The last packet successfully received from the server was 3,607 milliseconds ago. The last packet se ...

  8. eclipse:项目启动MySQL报错:The last packet successfully received from the server was x milliseconds ago

    原因是数据库设置了连接回收时长.这个时候系统缓冲池不知道会继续使用被回收的连接导致报错 解决方法:Navicat可视化工具直接执行: wait_timeout=86400或者更大将回收空闲连接的时间变 ...

  9. 彻底解决The last packet successfully received from the server was * milliseconds ago问题

    1.修改mysql 的 wait_timeout参数(和interactive_timeout一起) 不推荐 2.如果用hibernate.必须手动配置连接池,最好是用c3p0连接池.如果不配,会使用 ...

最新文章

  1. iscsi网络磁盘共享
  2. 关于Map的key值的问题
  3. c/c++获取文件大小的方法
  4. wxWidgets:wxTreebook类用法
  5. 叶琰:AI压缩技术在追上传统编码技术
  6. VS Code 1.40 发布!可自行搭建 Web 版 VS Code!
  7. css3文字一行或多行展示,多余文字省略号(学习)超出隐藏
  8. 手机支持html5绘图性能,【高级系列】Canvas绘制性能专题
  9. HandlerMethodArgumentResolver 参数解析器
  10. js 定义函数的几种方法 以及如何调用
  11. 北向接口jms消息服务器,运行日志 - eSight V300R010C00SPC600 维护指南 18 - 华为
  12. ensp ethernet端口配置ip问题
  13. apple pay,--牛逼,
  14. VMware虚拟机 之 NAT模式详解
  15. 二、Vue 属性绑定、v-model的原理、绑定class、绑定style
  16. [辩论]以成败轮英雄是可取的——正方一辩稿
  17. 详解Oracle架构、原理、进程,学会世间再无复杂架构
  18. 不需要邮箱 修改Gitlab账号密码(亲测可用)
  19. [ 前端开发 ] label标签的使用
  20. Springboot毕设项目创新创业管理系统1f90rjava+VUE+Mybatis+Maven+Mysql+sprnig)

热门文章

  1. c4d怎么设置中文?CINEMA 4D中文设置详细教程
  2. TCP通信过程详解以及tcp长连接和短连接
  3. 去 “马赛克” 工具横空出世, 一秒还原!
  4. mysql数据库中有bond_price_[多选] 下列公允价值层次中,属于第三层输入值的有()。...
  5. UML(一)——面向对象方法与软件过程模型
  6. 基于python的pyshp库读取.shp数据来获取中国城市边界的经纬度数据,并生成hdf文件
  7. 972信息检索 | 第二章 信息检索的方法和技术
  8. Css hover时 取子元素 切换img 实现图片移入切换
  9. CSS 背景人物虚化+字体不虚化
  10. Jmeter-并发压测和持续性压测