mysql无法远程登录问题
- 环境:
客户端IP:192.168.1.109
服务器IP:192.168.1.171
服务器mysql:5.7
服务器系统:linux ubuntu server
我windows客户端登录mysql报错
登录提示报错
com.mysql.cj.jdbc.exceptions.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.
- 排错
这个问题范围很广,需要一步一步排查。
ping 192.168.1.171可以ping通,排除基本网络问题
检查防火墙 sudo ufw status 显示Status: inactive,防火墙已关闭(我在自己做实验可以全部关闭防火墙,如果生产中应该关闭某一个端口)
进入mysql
查看是否授权或是授权是否成功
!是授权成功的在这里插入图片描述
ps:授权命令
grant all privileges on . to ‘root’@‘192.168.1.109’ identified by ‘123456’ with grant option;
flush privileges;
然后一时不知道问题出在哪里
网上有说是设置等待时长,因为超过八小时连接会断掉,我设置为最长连接set global interactive_timeout=604800;也不可以。
最重要的部分来了:
最后发现是配置文件/etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 127.0.0.1
默认绑定的是本地,屏蔽掉可以访问。
附录:
mysql5.1配置文件位置:/usr/share/mysql/my-huge.cnf
mysql5.5配置文件位置:/etc/mysql/my.cnf
mysql5.7配置文件位置:/etc/mysql/mysql.conf.d/mysqld.cnf