[英]Just can't connect to MySQL EC2 ubuntu instance remotely
I know there are several threads about this, but I've tried everything and am at my wit's end- I would just like to be able to connect to a MySQL database hosted on EC2. 我知道有几个线程可以解决这个问题,但是我已经尝试了一切,并且尽我所能-我只想能够连接到EC2上托管的MySQL数据库。
I have added port 3306 to the security group for the instance on EC2. 我已将端口3306添加到EC2上实例的安全组。
I have removed bind_address (skip-networking is no longer used by default) from the my.cnf file and restarted MySQL. 我从my.cnf文件中删除了bind_address(默认情况下不再使用跳过网络)并重新启动MySQL。 I have also alternatively tried bind_address=(external IP, it starts with 54.) and bind_address=0.0.0.0.
我也尝试了bind_address =(外部IP,以54开头)和bind_address = 0.0.0.0。
UFW status is inactive. UFW状态为无效。
On the server, running: 在服务器上,运行:
mysql -u remote-user -p -h MY_EXTERNAL_IP
works! 作品! But it doesn't work from my client, I get:
但这对我的客户不起作用,我得到:
`ERROR 2003 (HY000): Can't connect to MySQL server on 'MY_EXTERNAL_IP' (111)`
I created my current MySQL user with: 我使用以下方法创建了当前的MySQL用户:
GRANT USAGE ON *.* TO 'remote-user'@'localhost' IDENTIFIED BY 'password';
GRANT USAGE ON *.* TO 'remote-user'@'%' IDENTIFIED BY 'password';
I even ran: 我什至跑了:
sudo iptables -P INPUT ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
sudo iptables -I INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
Telnet doesn't connect: Telnet无法连接:
echo X | telnet -e X MY_EXTERNAL_IP 3306
echo X | telnet -e X MY_EXTERNAL_IP 3306
telnet: Unable to connect to remote host: Connection refused
echo X | telnet -e X MY_EXTERNAL_IP 3306
telnet: Unable to connect to remote host: Connection refused
But it does connect to the ssh port: 但是它确实连接到ssh端口:
Trying 54.221.103.104...
Connected to 54.221.103.104.
and netstat -a | grep 'mysql'
和
netstat -a | grep 'mysql'
netstat -a | grep 'mysql'
gives: netstat -a | grep 'mysql'
给出:
tcp 0 0 *:mysql *:* LISTEN
unix 2 [ ACC ] STREAM LISTENING 20762 /var/run/mysqld/mysqld.sock
Please, I'm at my wit's end. 拜托,我快要死了。 I just can't figure out what's wrong with this, I've been working on it for hours.
我只是想不通这是怎么回事,我已经研究了好几个小时。
comment line in /etc/mysql/my.cnf
that says: bind-address 127.0.0.1
this is the reason, I spend some 20-30 mins to figure out why it happens with disabled firewall :) this line makes Your server to listen only to calls from localhost on this port. /etc/mysql/my.cnf
中的/etc/mysql/my.cnf
行表示: bind-address 127.0.0.1
这是原因,我花了大约20-30分钟来弄清楚为什么在禁用防火墙的情况下会发生这种情况:)这行使您的服务器可以监听仅用于从此端口上的本地主机的调用。 Ofcourse You have to restart mysql service after this. 当然,这之后您必须重新启动mysql服务。
change the bind address in /etc/mysql/my.cnf from 127.0.0.1 to 0.0.0.0 has solved my issue and I was able to TELNET remotely on port 3306 without issues. 将/etc/mysql/my.cnf中的绑定地址从127.0.0.1更改为0.0.0.0已解决了我的问题,并且我能够在端口3306上远程TELNET而没有问题。
Also make sure your mysql user is not set only as a localhost mysql user and has the proper privileges. 还要确保您的mysql用户不仅设置为本地mysql用户,而且具有适当的特权。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.