Summary of database exceptions

Suddenly the database is unavailable and keeps reporting errors:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

 

Scenario: The above problem is caused by the configuration of the mysql5 database. mysql5 defaults its connection wait time (wait_timeout) to 8 hours.

Its value can be viewed in its client program like this:

mysql> show global variables like 'wait_timeout';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| wait_timeout  | 605800 |
+---------------+--------+
1 row in set (0.00 sec)

 28800 seconds, or 8 hours. 

If during wait_timeout seconds, the database connection (java.sql.Connection) has been in a waiting state, mysql5 will close the connection. At this point, your Java application's connection pool still legally holds a reference to that connection. When using this connection for database operations, the above error is encountered. This explains the problem why my program cannot log in the next day

 

Specific measures 1: In the configuration of the jdbc connection url, you can attach "autoReconnect=true", but this only works for versions before mysql5. Adding "validation query" doesn't seem to help either. (valid before 5.0)

Specific measures 2: Set the waiting timeout to 21 days and add a line to /etc/my.cnf : wait_timeout=1814400

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326258344&siteId=291194637