后台报com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failu问题的解决方案

问题:

今早,发现昨天部署的JAVA-WEB服务,不正常启动了,于是查看后台日志,发现

后台报com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failu问题的解决方案_第1张图片

11:07:05.358 [Druid-ConnectionPool-Create-1102883776] ERROR com.alibaba.druid.pool.DruidDataSource - create connection holder error
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,003 milliseconds ago.  The last packet sent successfully to the server was 1,003 milliseconds ago.
	at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:172) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:1518) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:1487) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.alibaba.druid.pool.DruidConnectionHolder.(DruidConnectionHolder.java:143) ~[druid-1.0.29.jar:1.0.29]
	at com.alibaba.druid.pool.DruidConnectionHolder.(DruidConnectionHolder.java:83) ~[druid-1.0.29.jar:1.0.29]
	at com.alibaba.druid.pool.DruidDataSource.put(DruidDataSource.java:1890) [druid-1.0.29.jar:1.0.29]
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2143) [druid-1.0.29.jar:1.0.29]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

解决:

打开navicat,进行解决

1、选择navicat的"工具-->命令列界面"

后台报com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failu问题的解决方案_第2张图片

 2、查看WAIT_TIMEOUT的值

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

mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
1109 - Unknown table 'SESSION_VARIABLES' in information_schema
mysql> set session WAIT_TIMEOUT=1814400;
Query OK, 0 rows affected (0.01 sec)

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

mysql> show global variables like 'timeout';
Empty set

mysql> set global WAIT_TIMEOUT=1814400;
Query OK, 0 rows affected (0.00 sec)

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

mysql> 

后台报com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failu问题的解决方案_第3张图片

3、再次刷新JAVA-WEB界面,成功

后台报com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failu问题的解决方案_第4张图片

后台报com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failu问题的解决方案_第5张图片 总结:

1. 控制连接最大空闲时长的wait_timeout参数。
2. 对于非交互式连接,类似于jdbc连接wait_timeout的值继承自服务器端全局变量wait_timeout(set session WAIT_TIMEOUT=1814400;是不起作用的,只有set global WAIT_TIMEOUT=1814400;才行)
    对于交互式连接,类似于mysql客户单连接,wait_timeout的值继承自服务器端全局变量interactive_timeout。
3. 判断一个连接的空闲时间,可通过show processlist输出中Sleep状态的时间。

后台报com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failu问题的解决方案_第6张图片

你可能感兴趣的:(解决方案,#,mysql,#,调优,mysql控制连接最大空闲时长,全局变量wait_time,mysql的jdbc异常,通信link,failure,jdbc非交互式连接)