栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

MySql连接报错communications link failure疑难问题

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MySql连接报错communications link failure疑难问题

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

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
1 出现原因

java连接数据库时出现Communications link failure怎么都登录不上

2 解决方案(我这种情况无效) 方法1
【1】登录mysql,cmd命令
mysql -h主机地址 -u用户名 -p用户密码(例如 mysql -hlocalhost -uroot -p123456)

【2】查看wait_timeout,cmd命令:
show global variables like 'wait_timeout';


【3】若wait_timeout太小,修改之。cmd命令:
set global wait_timeout=604800;
set global interactive_timeout=604800;
方法2
连接URL上添加参数:&autoReconnect=true
3 其他原因排查

如果试过上面两个方法都没有解决的话,排查服务器环境,及数据库端口是否有问题。

经过排查,如果数据库端口通过nginx反向代理,或者数据库端口通过其他服务器进行代理操作的话,是nginx反向代理超时导致的无法连接数据库

需要修改nginx的配置文件,通过steam代理mysl

stream {
     upstream mysql {
         zone myapp1 64k;
         server localhost:3306 weight=1 max_fails=3 fail_timeout=30s;
     }
     server {
         listen 10086;
         proxy_connect_timeout 1s;
         proxy_timeout 3s;
         proxy_pass mysql;
    }
}

其他情况,也可以同理排查mysql端口是否进行过代理

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/388687.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号