MySQL 鏈接錯誤Can't connect to MySQL server on ' '(61)

有一個帳戶 tt 沒法從遠程鏈接數據庫,報錯 Can't connect to MySQL server on '<remote-ip>' (61)node

一、查看該用戶是否有遠程登陸的權限

mysql> SELECT User, Host FROM mysql.user;
+-----------+-----------+
| User      | Host      |
+-----------+-----------+
| tt        | %         |
| mysql.sys | localhost |
| root      | localhost |
| Laily     | %        |
| ttt       | %        |
+-----------+-----------+
5 rows in set (0.00 sec)

很顯然,tt 是容許從其它服務器登錄的。mysql

二、查看 MySQL Server 是否是監聽了 3306 端口

[root@centos-linux ~]# 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 0.0.0.0:22              0.0.0.0:*               LISTEN      0          16801      1507/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      0          17222      1970/master
tcp6       0      0 :::3306                 :::*                    LISTEN      27         46396      22054/mysqld
tcp6       0      0 :::22                   :::*                    LISTEN      0          16803      1507/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      0          17223      1970/master
udp        0      0 0.0.0.0:68              0.0.0.0:*                           0          49600      22999/dhclient
udp        0      0 0.0.0.0:43504           0.0.0.0:*                           0          48850      22999/dhclient
udp6       0      0 :::47875                :::*                                0          48851      22999/dhclient

我在這裏也沒有問題,這裏若是沒有監聽3306端口或者只監聽了localhost(0.0.0.0表示監聽全部),則在my.cnf添加下面這一行linux

bind-address = 0.0.0.0

三、若是服務器是 CentOS7,將 MySQL 服務加入防火牆

[root@centos-linux ~]# sudo firewall-cmd --zone=public --permanent --add-service=mysql
success
[root@centos-linux ~]# sudo systemctl restart firewalld

個人重啓防火牆以後就能正常訪問了。sql

相關文章
相關標籤/搜索