admin管理员组文章数量:1618689
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端口是否进行过代理
本文标签: 报错疑难问题mysqlCommunicationsfailure
版权声明:本文标题:MySql连接报错communications link failure疑难问题 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1728784308a1173127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论