mysql 報錯 Communications link failure
一、問題
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 12 ms ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3009) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2895) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3438) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422) at com.victor_01.Jdbc_test.main(Jdbc_test.java:29) Caused by: java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2452) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2906) ... 8 more
二、解決問題步驟
1.檢查你的資料庫連線地址(配置檔案中的url)是否正確.
2.有可能是由mysql5資料庫的配置引起的。mysql5將其連線的等待時間(wait_timeout)預設為8小時。在其客戶程式中可以這樣來檢視其值:
mysql > show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)
28800 seconds,也就是8小時,如果在wait_timeout秒期間內,資料庫連線(java.sql.Connection)一直處於等待狀態,mysql5就將該連線關閉。這時,你的Java應用的連線池仍然合法地持有該連線的引用。當用該連線來進行資料庫操作時,就碰到上述錯誤。
解決方式:
2.1.mysql5以前的版本可以直接在jdbc連線url的配置中附加上“autoReconnect=true”。
2.2.將mysql的全域性變數wait_timeout的值修改為最大。檢視mysql5的手冊,發現windows和linux下wait_timeout的最大值分別是24天和365天。
(1).在檔案my.ini的最後增加一行:wait_timeout=1814400。(該檔案,windows下在mysql的安裝目錄下,linux下位置為/etc/my.ini)
(2).重啟mysql。
3.如果經過了以上的步驟,你的問題依舊沒有的到解決,則建議你修改下你程式中的mysql驅動的版本。
三、總結
透過本問題的解決,我們認識到如果碰到問題,首先不要慌,然後從最近的位置進行排查,最後一定能夠完美解決問題。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12798004/viewspace-2151901/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 經常報錯:Communications link failureAI
- com.mysql.jdbc.CommunicationsException: Communications link failureMySqlJDBCExceptionAI
- 應用端連線MySQL資料庫報Communications link failureMySql資料庫AI
- 【Azure 應用服務】App Service 無法連線到Azure MySQL服務,報錯:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failureAPPMySqlJDBCExceptionAI
- 解決Java程式連線mysql資料庫出現CommunicationsException: Communications link failure錯誤的問題JavaMySql資料庫ExceptionAI
- MySQL could not be resolved: Temporary failure in name resolution報錯解決方法MySqlAI
- cnpm link 報錯解決辦法NPM
- Assertion failure 錯誤AI
- 解決Vagrant報錯Warning: Authentication failure. Retrying問題AI
- 安裝Oracle cluster報錯 Failure at final check of Oracle CRS Stack 10OracleAI
- Mysql8.0 報錯MySql
- tar解壓報錯——Not found in archive tar: Exiting with failure status due to previous errorsHiveAIError
- mysql執行報錯mysql.sockMySql
- [排錯]安裝Oracle 10g RAC報Failure at final check of Oracle CRS stack 10錯誤Oracle 10gAI
- MySql報錯(持續更新)MySql
- mysql checksum 報錯問題。MySql
- MYSQL SOURCE報錯 ERROR: ASCIIMySqlErrorASCII
- MySQL下的DB LinkMySql
- mysql報錯ERROR 1093MySqlError
- 【Mysql】into outfile報錯的問題MySql
- 安裝mysql 5.5.14 報錯MySql
- mysql報錯程式碼彙總MySql
- mysql登陸報錯mysql: unknown variable 'basedir=MySql
- 資料庫hang死,前面報錯ORA-12570: TNS:packet reader failure資料庫AI
- idea執行java專案main方法報build failure錯誤的解決方法IdeaJavaAIUI
- Http failure response 0 Unknown error 錯誤分析HTTPAIError
- MySQL查詢取別名報錯MySql
- mysql 8.0 使用 navicat 登入報錯MySql
- mysql5.6 mysqldump備份報錯MySql
- Mysql自動處理同步報錯MySql
- MySQL 建立儲存過程報錯MySql儲存過程
- MySQL報錯 Error_code: 1045MySqlError
- 安裝MYSQL ODBC5.3報錯MySql
- mysql複製報錯案例處理MySql
- 透過Amoeba連線mysql報錯MySql
- 練習使用list failure,advise failure; repair failure;AI
- Shiro報錯-[org.apache.shiro.mgt.AbstractRememberMeManager] - There was a failure while trying to retrieve remembered principals.ApacheREMAIWhile
- oracle alert日誌檔案報錯ORA-27302: failure occurred at: skgpspawn3OracleAI