0922e75efe973694fd52cf797bfd5258b9f89180
By:
hauvo

NodeJs on DigitalOcean cannot connect to MySQL database on Amazon RDS

April 18, 2015 2.5k views
DigitalOcean Networking

Hi all,
We deployed the NodeJS web service on DigitalOcean and connect to MySQL database on Amazon RDS. i can use Navicat Premium to remote to MySQL RDS and also works fine with NodeJS localhost (it means my application on localhost can connect to RDS database)

But when i deployed my app to DigitalOcean server. It cannot connect to MySQL RDS. The connect was timed out.

I use command to view opening port:

iptables -L

And the result is:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3000
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:mysql
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3000
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:mysql
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:mysql

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:mysql

I see output and input also opened for port 3306. But NodeJs still cannot connect. The problem is DigitalOcean droplet does not open port 3306 and NodeJS application cannot connect to outside via this port.

(P/S: Amazon RDS also open all ports and anywhere for IP)

Please help me, thanks

1 Answer

Check the security groups on AWS, they may be blocking external connections.

Use telnet to check if the RDS hostname is accessible from your Droplet.

telnet myinstance.123456789012.us-east-1.rds.amazonaws.com 3306

You can also use the MySQL command.

mysql -hmyinstance.123456789012.us-east-1.rds.amazonaws.com -uusername -ppassword
Have another answer? Share your knowledge.