1130主机'amazon-ec2-ip'不允许连接到该MySQL服务器 [英] 1130 Host 'amazon-ec2-ip' is not allowed to connect to this MySQL server

查看:129
本文介绍了1130主机'amazon-ec2-ip'不允许连接到该MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一个EC2服务器访问我的Amazon EC2服务器之一上的mysql DB时遇到问题.我通读了有关为mysql提供适当权限以从外部IP地址进行访问的各种文章,下面是我遵循的步骤:

I am facing a problem in accessing the mysql DB on one of my Amazon EC2 servers from another EC2 server. I read through various articles regarding providing appropriate permissions for mysql to be accessed from external IP addresses, and here are the steps that I followed:

  1. 在主机EC2实例上打开了端口3306,以允许外部Mysql连接.
  2. 在文件/etc/mysql/my.cnf中,将绑定地址"从"127.0.0.1"更改为"0.0.0.0".
  3. 使用root用户打开mysql,并执行以下命令: 将所有特权授予.到worker @'ec2-ip-address',由'password'标识;
  1. Opened port 3306 on my host EC2 instance to allow for external Mysql connection.
  2. In the file /etc/mysql/my.cnf, changed the "bind-address" from "127.0.0.1" to "0.0.0.0".
  3. Opened mysql using root, and executed the following command: GRANT ALL PRIVILEGES on . to worker@'ec2-ip-address' IDENTIFIED BY 'password';

根据我阅读的所有博客/文章,这应该已经解决了该问题,但是我不断收到以下错误:

As per all the blogs/articles that I read, this should have solved the issue, but i keep getting the following error:

1130  Host 'amazon-ec2-ip' is not allowed to connect to this MySQL server

我为EC2实例提供的ip地址是创建实例时生成的弹性IP.为了验证问题是否特定于EC2,我尝试为其他静态IP地址"执行命令"3".现在,这对我有用(即,我能够从该远程服务器登录到mysql主机),因此可以确保上述步骤是正确的.

The ip address I was providing for the EC2 instance was an elastic IP that gets generated when you create an instance. To verify whether the issue is specific to EC2, I tried executing the command "3" for a different "static ip address". Now, this worked for me (i.e. I was able to login to the mysql host from that remote server), so it is sure that the above steps are correct.

为什么Amazon EC2 ip地址不起作用?

Why is the Amazon EC2 ip address not working?

推荐答案

发布此问题后,当我在工作时,我意识到自己甚至无法ping通EC2服务器或telnet.所以一些基本的东西一定是错误的.最后,一个朋友帮助我解决了这个问题.如我所料,该问题非常针对EC2.

After posting this problem, as I was working, I realized that I wasn't even able to ping to the EC2 server or telnet to it. So something basic had to be wrong. Finally a friend helped me out with the problem. As I had expected, the problem was very specific to EC2.

详细信息如下:

创建EC2实例时,我们获得的外部IP地址类似于:ec2-XX-XXX-XXX-XX.ap-southeast-1.compute.amazonaws.com

When we create an EC2 instance, we get an external IP address which is similar to: ec2-XX-XXX-XXX-XX.ap-southeast-1.compute.amazonaws.com

在mysql中设置权限时,我向上述IP地址授予了权限,即:

While setting the permissions in the mysql I was granting the permissions to the above IP address, i.e.:

GRANT ALL PRIVILEGES on . to worker@'ec2-XX-XXX-XXX-XX.ap-southeast1.compute.amazonaws.com' IDENTIFIED BY 'password';

当您尝试从另一个本地EC2实例与EC2实例进行通信时,此方法不起作用.为此,您需要提供EC2实例的内部ip地址",可以使用ip命令找到它:

This does not work when you try to communicate to an EC2 instance from another local EC2 instance. For this, you need to provide the 'internal ip address" of the EC2 instance, which can be found using the ip command:

ip a:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host 
valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 12:31:41:02:58:47 brd ff:ff:ff:ff:ff:ff
inet **XX.XX.XX.XXX/23** brd YY.YYY.YY.YYY scope global eth0
inet6 fe80::1031:41ff:fe02:5847/64 scope link 
valid_lft forever preferred_lft forever

要使事情正常运行,您需要向IP地址"XX.XXX.XX.XXX/23"授予权限,它应该可以工作.同样,在连接到"mysql"数据库时,提供给mysql命令的主机名也应该是主机EC2实例的内部ip地址".

To get things working correctly, you need to grant the permission to the ip address --"XX.XXX.XX.XXX/23", and it should work. Similarly, while connecting to the "mysql" database, the hostname provided to the mysql command should also be the "internal ip address" of the host EC2 instance.

这篇关于1130主机'amazon-ec2-ip'不允许连接到该MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆