com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 126,421,823 milliseconds ago. The last packet sent successfully to the server was 126,421,823 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.
java
解決辦法:mysql
修改mysql配置文件,更改鏈接失效時間linux
mysql﹥sql
mysql﹥ show global variables like ‘wait_timeout’;數據庫
+—————+———+windows
| Variable_name | Value |tomcat
+—————+———+app
| wait_timeout | 28800 |ide
+—————+———+測試
1 row in set (0.00 sec)
28800 seconds,也就是8小時。
若是在wait_timeout秒期間內,數據庫鏈接(java.sql.Connection)一直處於等待狀態,mysql5就將該鏈接關閉。這時,你的Java應用的鏈接池仍然合法地持有該鏈接的引用。當用該鏈接來進行數據庫操做時,就碰到上述錯誤。這解釋了爲何個人程序次日不能登陸 的問題。
你可能會想到在tomcat的數據源配置中有沒有辦法解決?的確,在jdbc鏈接url的配置中,你能夠附上「autoReconnect=true」,但這僅對mysql5之前的版本起做用。增長「validation query」彷佛也無濟於事。
本人以爲最簡單的辦法,就是對症下藥:既然問題是由mysql5的全局變量wait_timeout的缺省值過小引發的,咱們將其改大就行了。
查看mysql5的手冊,發現對wait_timeout的最大值分別是24天/365天(windows/linux)。以windows爲 例,假設咱們要將其設爲21天,咱們只要修改mysql5的配置文件「my.ini」(mysql5 installation dir),增長一行:wait_timeout=1814400
須要從新啓動mysql5。
linux系統配置文件:/etc/my.cnf
測試顯示問題解決了。
也能夠直接設置
mysql修改wait_timeout
mysql mysql> show global variables like ‘wait_timeout’;
其默認值爲8小時
mysql的一個connection空閒時間超過8小時,mysql會自動斷開該鏈接。
1.修改配置
vi /etc/my.cnf
[mysqld] wait_timeout=10
# /etc/init.d/mysql restart
2.直接用sql命令行修改 mysql> set global wait_timeout=604800;
除了wait_timeout,還有一個’interactive_timeout’
一樣能夠執行SHOW GLOBAL VARIABLES LIKE ‘interactive_timeout’;來查詢 執行set global interactive_timeout=604800;來設置