MySQL 5.1 exceeds the default 8-hour idle Time workaround (Error: Com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure)

Source: Internet
Author: User

Error:

MySQL first time the next morning to connect the super-times wrong,

Com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link Failure

Reason:

The above problem is caused by the configuration of the MYSQL5 database. MySQL5 the wait time (Wait_timeout, interactive_timeout) of its connection by default to 8 hours. In its client program, you can view its values like this:

Mysql> show global variables like ' wait_timeout ';mysql> show global variables like ' interactive_timeout ';

If the database connection (java.sql.Connection) is in a waiting state for wait_timeout seconds, MYSQL5 closes the connection. At this point, your Java app's connection pool still legitimately holds a reference to that connection. This error is encountered when the connection is used for database operations. This explains why my program cannot log on the next day.

Workaround:

In My.ini (Windows) or/ETC/MY.CNF (Linux), under [Mysqld], add:

wait_timeout=31536000interactive_timeout=31536000

Such as:

Restart MySQL to see the timeout setting again:

[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 exceeds the default 8-hour idle Time workaround (Error: Com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link Failure)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.