mysql 5.1超過預設8小時空閑時間解決辦法(錯誤:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)

來源:互聯網
上載者:User

標籤:res   資料庫操作   jdb   value   ica   預設   start   解決辦法   color   

報錯:

MySQL第二天早上第一次連線逾時報錯,

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 

原因:

上述問題是由mysql5資料庫的配置引起的。mysql5將其串連的等待時間(wait_timeout 、interactive_timeout)預設為8小時。在其客戶程式中可以這樣來查看其值:

mysql> show global variables like ‘wait_timeout‘;mysql> SHOW GLOBAL VARIABLES LIKE ‘interactive_timeout‘;

如果在wait_timeout秒期間內,資料庫連接(java.sql.Connection)一直處於等待狀態,mysql5就將該串連關閉。這時,你的Java應用的串連池仍然合法地持有該串連的引用。當用該串連來進行資料庫操作時,就碰到上述錯誤。這解釋了為什麼我的程式第二天不能登入 的問題。 

 

解決辦法:

在my.ini(windows) 或者/etc/my.cnf(linux) 中的 [mysqld]下添加:

wait_timeout=31536000interactive_timeout=31536000

如:

 

重啟mysql再次查看逾時設定:

[[email protected] /]#  /etc/init.d/mysqld restart
...mysql> SHOW GLOBAL VARIABLES LIKE ‘interactive_timeout‘;+---------------------+----------+| Variable_name | Value |+---------------------+----------+| interactive_timeout | 31536000 |+---------------------+----------+1 row in set (0.00 sec)mysql> show global variables like ‘wait_timeout‘;+---------------+----------+| Variable_name | Value |+---------------+----------+| wait_timeout | 31536000 |+---------------+----------+1 row in set (0.00 sec)

 

mysql 5.1超過預設8小時空閑時間解決辦法(錯誤:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.