MySQL连接池配置——超时异常和处理

本文介绍了在MySQL 8.0.15版本中遇到的连接超时问题,详细分析了wait_timeout和interactive_timeout参数对连接的影响。内容包括数据库连接配置,异常错误的分析,以及C3P0连接池的优化建议,如设置testConnectionOnCheckout、testConnectionOnCheckin和idleConnectionTestPeriod来避免连接异常。
摘要由CSDN通过智能技术生成

前言

MySQL版本:MySQL 8.0.15

数据库连接驱动版本:mysql-connector-java-8.0.15.jar

连接池版本:c3p0-0.9.5.2.jar

连接配置

#数据库驱动
jdbc.driver=com.mysql.cj.jdbc.Driver
#数据库连接
jdbc.url=jdbc:mysql://localhost:3306/miniss?characterEncoding=utf8&amp&serverTimezone=UTC&amp&autoReconnect=true
#用户名
jdbc.username=root
#用户密码
jdbc.password=123456

异常错误

Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 68,560,034 milliseconds ago.  The last packet sent successfully to the server was 68,5
60,034 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 serv
er configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
; SQL []; The last packet successfully received from the server was 68,560,034 milliseconds ago.  The last packet sent successfully to the server was 68,560,034 milliseconds ago. is longer than the server conf
igured 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.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 
68,560,034 milliseconds ago.  The last packet sent successfully to the server was 68,560,034 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 p
roblem.
        at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
        at com.sun.proxy.$Proxy19.selectOne(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
        at com.sun.proxy.$Proxy20.adminLogin(Unknown Source)
        at 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值