栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

mysql设置会话超时时间

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mysql设置会话超时时间

问题

mysql的默认设置下,当一个连接的空闲时间超过8小时后,mysql 就会断开该连接,而连接池认为连接依然有效。在这种情况下,如果客户端代码向连接池请求连接的话,连接池就会把已经失效的连接返回给客户端,客户端在使用该失效连接的时候即抛出异常。类似如下异常:

2022-07-28 19:40:05.618 [http-nio-7072-exec-7] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper --info-- SQL Error: 0, SQLState: null 2022-07-28 19:40:05.618 [http-nio-7072-exec-7] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper --info-- connection disabled 2022-07-28 19:40:05.625 [http-nio-7072-exec-7] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/admin-api].[dispatcherServlet] --info-- Servlet.service() for servlet [dispatcherServlet] in context with path [/admin-api] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not prepare statement] with root cause java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

解决方法

框架用的druid连接池,目前mysql8暂未找到配置自动重连的有效实现方式,在配置文件把mysql会话超时时间改成wait_timeout = 432000和interactive_timeout = 432000来解决,即设置超时时间为5天。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1031502.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号