MySQL的Communications link failure

最近要從數據庫讀取信息,但連接其他庫都沒問題,只有其中一個庫老報錯:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. the driver has not received any packets from the server.


網上查到的符合我環境的,應該是我的連接數太多,導致MySQL連接數用完,所以優化代碼,讓多次連接公用一個connection;連接用完後,關閉。

此外,設置自動重連也能有一定幫助,但ms官方不太建議設置自動重連。

自動重連,在java中只需把連接的server字符串中添加:

jdbc:mysql://[ip]:[port]/[table]?autoReconnect=true&failOverReadOnly=false&maxReconnects=10



其中這兩篇文章比較好:

http://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally
http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章