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

Mac sequel Pro链接时报错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、查看该用户是否有远程登录的权限

  1.  mysql> SELECT * FROM mysql.user;
  2.  +-----------+-----------+
  3.  | User | Host |
  4.  +-----------+-----------+
  5.  | M | % |
  6.  | mysql.sys | localhost |
  7.  | root | localhost |
  8.  | tommy | % |
  9.  | showhilllee | % |
  10.  +-----------+-----------+
  11.  5 rows in set (0.00 sec)

  很显然,M是允许从其它服务器登陆的。

2、查看 MySQL Server 是不是监听了 3306 端口

  执行命令netstat -tulpen

  1.  netstat -tulpen
  2.  
  3.  Active Internet connections (only servers)
  4.  Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
  5.  tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 16801 1507/sshd
  6.  tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 0 17222 1970/master
  7.  tcp6 0 0 :::3306 :::* LISTEN 27 46396 22054/mysqld
  8.  tcp6 0 0 :::22 :::* LISTEN 0 16803 1507/sshd
  9.  tcp6 0 0 ::1:25 :::* LISTEN 0 17223 1970/master
  10.  udp 0 0 0.0.0.0:68 0.0.0.0:* 0 49600 22999/dhclient
  11.  udp 0 0 0.0.0.0:43504 0.0.0.0:* 0 48850 22999/dhclient
  12.  udp6 0 0 :::47875 :::* 0 48851 22999/dhclient

我在这里也没有问题。

这里如果没有监听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 

重启防火墙之后就能正常访问了。

 
原文地址:https://www.cnblogs.com/wupeng88/p/11989598.html