MySQL连接如果8小时未使用,在查询使用到该连接会报:
异常名称:com.mysql.jdbc.CommunicationsException
异常信息: Communications link failure due to underlying exception
如果是MySQL5以前的版本,需要修改连接池配置中的URL,添加autoReconnect=true
如果是MySQL5 以后的版本,需要修改my.cnf(或者my.ini)文件,在[mysqld]后面添加
wait_timeout = 172800
interactive-timeout = 172800
单位都是秒,记得必须都添加,否则不起作用,通过show variables查看wait_timeout的值。