简体   繁体   中英

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.

  1. I have added port 3306 to the security group for the instance on EC2.

  2. I have removed bind_address (skip-networking is no longer used by default) from the my.cnf file and restarted MySQL. I have also alternatively tried bind_address=(external IP, it starts with 54.) and bind_address=0.0.0.0.

  3. UFW status is inactive.

  4. 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)`
  1. I created my current MySQL user with:

    GRANT USAGE ON *.* TO 'remote-user'@'localhost' IDENTIFIED BY 'password';

    GRANT USAGE ON *.* TO 'remote-user'@'%' IDENTIFIED BY 'password';

  2. 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

  3. Telnet doesn't connect:

    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

But it does connect to the ssh port:

Trying 54.221.103.104...
Connected to 54.221.103.104.

and netstat -a | grep 'mysql' netstat -a | grep 'mysql' gives:

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. Ofcourse You have to restart mysql service after this.

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.

Also make sure your mysql user is not set only as a localhost mysql user and has the proper privileges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM