无法连接到远程 MySQL 服务器,错误 61

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16161889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:26:25  来源:igfitidea点击:

Can't connect to remote MySQL server with error 61

mysql

提问by Wenhao Ji

When I tried to connect the remote MySQL server by using command line mysql -h <remote-ip> -u any_existing_users -por any other mysql client such as phpmyadmin, it didn't work and the error hint was

当我尝试使用命令行mysql -h <remote-ip> -u any_existing_users -p或任何其他 mysql 客户端(例如 phpmyadmin)连接远程 MySQL 服务器时,它不起作用,错误提示是

ERROR 2003 (HY000) Can't connect to MySQL server on '<remote-ip>' (61)

But, when I tried ssh <remote-ip>and connected the MySQL locally by mysql -u root -p, there is no problem.

但是,当我尝试ssh <remote-ip>通过 本地连接 MySQL 时mysql -u root -p,没有问题。

Here is part of the user table(SELECT User, Host FROM mysql.user;):

这是用户表(SELECT User, Host FROM mysql.user;)的一部分:

+------------------+----------------+
| User             | Host           |
+------------------+----------------+
| root             | %              |
| other_users      | <remote-ip>    |
| root             | localhost      |
+------------------+----------------+

Here is the iptable:

这是iptable:

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    RH-Firewall-1-INPUT  all  --  0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    RH-Firewall-1-INPUT  all  --  0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

Chain RH-Firewall-1-INPUT (2 references)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 255 
3    ACCEPT     esp  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     ah   --  0.0.0.0/0            0.0.0.0/0           
5    ACCEPT     udp  --  0.0.0.0/0            224.0.0.251         udp dpt:5353 
6    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:631 
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:631 
8    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
9    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
10   REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
11   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306 

So, what's the problem?

所以有什么问题?

回答by Kaffee

Check if your mysql server is listening on a socket with netstat:

检查您的 mysql 服务器是否正在使用 netstat 侦听套接字:

netstat -tulpen

and search for 3306.

并搜索 3306。

If not or if only on localhost, check my.cnf and search the bind-addressline and change it to:

如果没有或仅在本地主机上,请检查 my.cnf 并搜索该bind-address行并将其更改为:

bind-address = 0.0.0.0

then restart the server and try again.

然后重新启动服务器并重试。

回答by Haimei

Check status:

检查状态:

netstat -tulpen

Modify your configuration:

修改您的配置:

nano /etc/mysql/my.cnf
# Edit:
bind-address = 0.0.0.0

Enter mysql and give privileges:

进入mysql并赋予权限:

mysql -umyuser -pmypassword
# Run:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

Restart mysql

重启mysql

/etc/init.d/mysql restart

回答by ulou

With MySql 5.7they changed files so bind-addressare now in:

随着MySql 5.7他们改变文件,因此bind-address现在在:

/etc/mysql/mysql.conf.d/mysqld.cnf

instead of:

代替:

/etc/mysql/my.cnf

回答by user3127882

If you run MAMP, do not forget to allow access (mySQL panel, check "Allow network access to MySQL")

如果您运行 MAMP,请不要忘记允许访问(mySQL 面板,选中“允许网络访问 MySQL”)

回答by rcerecedar

I had this problem just after installing Centos 7 on a server. I could′t access to it through Mysql Workbench in a remote computer.

在服务器上安装 Centos 7 后,我遇到了这个问题。我无法在远程计算机上通过 Mysql Workbench 访问它。

The problem was in the firewall configuration. Eventually, the solution came when doing:

问题出在防火墙配置中。最终,解决方案来了:

sudo firewall-cmd --zone=public --permanent --add-service=mysql

And then, restart the firewall:

然后,重新启动防火墙:

sudo systemctl restart firewalld

回答by Beth Coder

It can be a problem related to firewall or try this:

可能是与防火墙相关的问题或尝试以下操作:

GO to Server Admin -> MySQL -> Settings -> check: Allow Network Connections

转到服务器管理 -> MySQL -> 设置 -> 检查:允许网络连接

Then restart MySQL

然后重启MySQL

回答by Zaziki

Take a look at the "Causes of Access-Denied Errors" from MySQL.

查看 MySQL 的“拒绝访问错误的原因”。

http://dev.mysql.com/doc/refman/5.1/en/access-denied.html

http://dev.mysql.com/doc/refman/5.1/en/access-denied.html

Possibile is there a failed configuration on your server or a other program is using the same port? Or is the server bind on "127.0.0.1"? Try changing the the my.cnf file.

可能是您的服务器上的配置失败或其他程序正在使用相同的端口?还是服务器绑定在“127.0.0.1”上?尝试更改 my.cnf 文件。

回答by Richard

For MacOS:

对于 MacOS:

mysql -uroot -p

mysql> use mysql;

# View user's host
mysql> select 'host' from user where user='root';
# Update host to '%'
mysql> update user set host='%' where user='root';

mysql> flush privileges;
mysql> quit
vim /usr/local/etc/my.cnf
# Default Homebrew MySQL server config
[mysqld]
bind-address = 0.0.0.0
# Restart and reconnect MySQL
mysql.server restart
mysql -uroot -h0.0.0.0 -p