今天部署项目上线 然后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</v