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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 應用端連線MySQL資料庫報Communications link failureMySql資料庫AI
- 【Azure 應用服務】App Service 無法連線到Azure MySQL服務,報錯:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failureAPPMySqlJDBCExceptionAI
- cnpm link 報錯解決辦法NPM
- tar解壓報錯——Not found in archive tar: Exiting with failure status due to previous errorsHiveAIError
- MySQL下的DB LinkMySql
- Mysql8.0 報錯MySql
- Http failure response 0 Unknown error 錯誤分析HTTPAIError
- mysql執行報錯mysql.sockMySql
- idea執行java專案main方法報build failure錯誤的解決方法IdeaJavaAIUI
- MySql報錯(持續更新)MySql
- mysql checksum 報錯問題。MySql
- Maven:Non-resolvable parent POM: Failure to find錯誤MavenAI
- E. Disrupting Communications
- 【譯】使用 Source Link 提高除錯效率除錯
- mysql報錯程式碼彙總MySql
- DCN-Digital Communications and NetworksGit
- 【MySQL】ERROR 1878 (HY000): Temporary file write failure.MySqlErrorAI
- python3.10呼叫郵件SMTP報錯: ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)解決PythonErrorAI
- MySQL查詢取別名報錯MySql
- Mysql自動處理同步報錯MySql
- mysql5.6 mysqldump備份報錯MySql
- MySQL更新卡住報錯lock wait timeoutMySqlAI
- mysql 8.0 使用 navicat 登入報錯MySql
- design for failureAI
- Communications--1--資料傳輸除錯記錄-bug採坑雷區除錯
- Mysql報錯注入原理分析(count()、rand()、group by)MySql
- 半同步複製報錯mysql8.0.25MySql
- laravel mysql批量提交報Access denied 錯誤LaravelMySql
- mysql匯入報錯怎麼解決?MySql
- mysql報1045錯誤是什麼意思MySql
- Redis4.0從庫複製報錯"master_link_status:down"處理一例RedisAST
- 報錯install_driver(mysql) failed: Attempt to reload DBD/mysql.pmMySqlAI
- Navicat連線centos裡mysql報錯Host is not allowed to connect to this MySQL serverCentOSMySqlServer
- Mysql資料庫報ERROR 1045 (28000)報錯及MySQL忘記密碼找回MySql資料庫Error密碼
- mysql 啟動報錯Can't connect to local MySQL server through socket '/data/mysql/mysql/mysql.sock'(111)MySqlServer
- MYSQL timestamp NOT NULL插入NULL的報錯問題MySqlNull
- MySql報錯:Lock wait timeout exceeded: try restadina transactionMySqlAIREST
- MySQL 啟動報錯 error while loading shared librariesMySqlErrorWhile