您的位置:首页 > 数据库 > MySQL

mysql连接等待超时引发的异常

2018-01-29 11:31 316 查看
当mysql链接空闲超过默认时长(没做配置的话),链接会自动断开,这时再去访问会发生如下异常:

### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException:
The last packet successfully received from the server was 216,960,986 milliseconds ago.
The last packet sent successfully to the server was 216,960,987 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.
### The error may exist in URL [jar:file:****]
### The error may involve ****-Inline
### The error occurred while setting parameters
### SQL: ****


为了避免此问题可以给mysql加一个配置:

idleConnectionTestPeriod: 3600

mysql会每隔3600自动去发起一条sql以保持数据库链接,另外这个时间一定要小于数据库链接的等待超时时间才行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: