ln12341234 2020-10-14 16:25 采纳率: 75%
浏览 1121
已采纳

mysql链接超时 is longer than the server configured value of 'wait_timeout'

1.问题描述

系统运行阶段出现报错 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 427,583,591 milliseconds ago. The last packet sent successfully to the server was 427,583,592 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.
实际上当前数据源配置文件已加上autoReconnect=true,
mysql wait_timeout 值为默认值8小时 28800
mysql版本:5.6.41
数据库链接池:tomcat jdbc

请问该如何解决。

2.相关配置

数据源配置文件:

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driver}" />
            <property name="url" value="jdbc:mysql://xxxx:3306/xxx?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
            <property name="maxActive" value="100" />
            <property name="maxIdle" value="50" />
            <property name="minIdle" value="5" />
            <property name="maxWait" value="-1" />
            <property name="validationQuery" value="SELECT 1" />
            <property name="testWhileIdle" value="true" />
            <property name="timeBetweenEvictionRunsMillis" value="60000" />
            <property name="minEvictableIdleTimeMillis" value="60000" />
            <property name="defaultAutoCommit" value="false" />
        </bean>

mysql配置文件:

[mysqld]
innodb_buffer_pool_size = 150G
 join_buffer_size = 256M
 sort_buffer_size = 20M
 read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
group_concat_max_len = 1024000

symbolic-links=0

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
transaction-isolation=READ-COMMITTED

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

3.错误信息

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 427,583,591 milliseconds ago. The last packet sent successfully to the server was 427,583,592 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.

  • 写回答

1条回答 默认 最新

  • SpringBoot中文社区 2020-10-14 17:02
    关注

    好像mysql官方不建议 使用autoReconnect参数,你换个数据源试试看?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?