MySQL 连接错误Can't connect to MySQL server on (61)

链接数据库时忽然遇到一个问题。Mac Navicat链接时报错Can’t connect to MySQL server on ‘xx.xx.xx.xx’ (61)。 PS. win版Navicat 报错Can’t connect to MySQL server on ‘xx.xx.xx.xx’ (10038) 其中xx.xx.xx.xx是ip地址。 #### 1、查看该用户是否有远程登录的权限 mysql> SELECT * FROM mysql.user; +-----------+-----------+ | User | Host | +-----------+-----------+ | M | % | | mysql.sys | localhost | | root | localhost | | tommy | % | | showhilllee | % | +-----------+-----------+ 5 rows in set (0.00 sec) 很显然,M是允许从其它服务器登陆的。 #### 2、查看 MySQL Server 是不是监听了 3306 端口 执行命令`netstat -tulpen` netstat -tulpen Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 0 753855 30154/redis-server tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 62981 7834/nginx: worker tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 16422 851/sshd 我在这里也没有问题。 这里如果没有监听3306端口或者只监听了localhost(0.0.0.0表示监听所有),则在my.cnf添加下面这一行 bind-address = 0.0.0.0 #### 3、如果服务器是 CentOS7,将 MySQL 服务加入防火墙 执行命令 sudo firewall-cmd --zone=public --permanent --add-service=mysql 返回success。然后继续执行 sudo systemctl restart firewalld 我的重启防火墙之后就能正常访问了。
联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3