在java项目上线后,第二天再重新运行项目的时候,出现了如下的错误:
CommunicationsException: The last packet successfully received from the server was 60,547,352 milliseconds ago. The last packet sent successfully to the server was 60,547,352 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.
初步查看了一下,网上很多说的把time_out时间修改的长一点。(可能是个解决办法)
我最后发现原因出在我在项目里开启里mysql的连接,但是没有关闭它。导致的这个错误。
分析一波:
在我们开启mysql服务后,正常如果我们没有修改mysql的服务时间,那么它默认是8个小时,也就是如果我们开启一个服务后,8小时之内没有人访问,那么这个连接就会自动断掉,当我们再次访问这个的时候,就会出现上面的错误。
解决办法:
就是在开启后,使用完成后,要及时关闭mysql连接,用到的时候再重新启用即可。(这个只是我的项目的解决办法,智者见智哈)