Cannot Connect To Private Network MySQL

August 30, 2018 1.1k views
MySQL Ubuntu 16.04

2 droplets same data center, same project.
Both droplets are behind the same firewall.

I am attempt to connect from Droplet 1 to MySQL on Droplet 2
however, I keep getting:
“ERROR 2003 (HY000): Can’t connect to MySQL server on”

telnet xx.xxx.xx.xx 3306
Trying xx.xxx.xx.xx…
telnet: Unable to connect to remote host: Connection refused

Telnet over port 22, 80, 443 is all fine.
I can ping ok.

I have set my mysql.cnf file to bind over 0.0.0.0
I have set up a user with the @ % for the sake of debugging the connection issue, but still no luck.
I restarted mysql
I flushed the privileges.

netstat -tulnp | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 23317/mysqld

What am I missing here?

Thank you!!

4 Answers

Hey friend!

I feel like the most likely cause here is firewall. Are you using our firewall or iptables/ufw/firewalld? If you’re using our firewall and have port 3306 open in it, try removing the firewall from the droplets just for kicks. Never hurts to rule it out. Otherwise, are you certain that the port is open in your firewall and above any other rule that might first reject the traffic?

Jarland

the forum is rejecting my reply as spam, so putting this in the answer section to help share more information.

Both droplets (Ubuntu 16) are behind the DigitalOcean firewall, so that should not be blocking anything as they are connected to each other via private network. I did open port 3306 on the DigitalOcean firewall and it had no effect.

iptables are not enabled:
service iptables stop
Failed to stop iptables.service: Unit iptables.service not loaded.

I ran ufw allow mysql
No change in connecting.

I ran ufw disable on both droplets
ufw disable
Firewall stopped and disabled on system startup

At this point 3306 is an open port in the digitalocean firewall.
ufw is completely disabled on both boxes

yet I still get:
telnet xx.xxx.xx.xx 3306
Trying xx.xxx.xx.xx…
telnet: Unable to connect to remote host: Connection refused

mysql -u username -p -h privateNetworkIP
Enter password:
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘xx.xx.xx.xx’ (111)

But:
telnet xx.xxx.xx.xx 22
Trying xx.xxx.xx.xx…
Connected to xx.xxx.xx.xx.
Escape character is ’^]’.
SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4

telnet on port 80 also works, but ssl port 443 fails like 3306

DigitalOcean Firewall Settings:
Inbound Rules
Type Protocol Port Range Sources

SSH TCP 22 All IPv4 All IPv6
HTTP TCP 80 All IPv4 All IPv6
HTTPS TCP 443 All IPv4 All IPv6
MySQL TCP 3306 All IPv4 All IPv6

Outbound Rules
Set the Firewall rules for outbound traffic. Outbound traffic will only be allowed to the specified ports. All other traffic will be blocked.
Type Protocol Port Range Destinations

ICMP ICMP All IPv4 All IPv6
All TCP TCP All ports All IPv4 All IPv6
All UDP UDP All ports All IPv4 All IPv6

Any other ideas?

I appreciate the help on this!

@dpp777 did you ever find a solution to this? I’m in the exact same boat as you.

Have another answer? Share your knowledge.