简体   繁体   English

DigitalOcean上的NodeJ无法连接到Amazon RDS上的MySQL数据库

[英]NodeJs on DigitalOcean cannot connect to MySQL database on Amazon RDS

We deployed the NodeJS web service on DigitalOcean and connect to MySQL database on Amazon RDS. 我们在DigitalOcean上部署了NodeJS Web服务,并连接到Amazon RDS上的MySQL数据库。 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) 我可以使用Navicat Premium远程访问MySQL RDS,也可以使用NodeJS localhost(这意味着我在localhost上的应用程序可以连接到RDS数据库)

But when i deployed my app to DigitalOcean server. 但是当我将我的应用程序部署到DigitalOcean服务器时。 It cannot connect to MySQL RDS. 它无法连接到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. 我看到输出和输入也为端口3306打开了。但是NodeJ仍然无法连接。 The problem is DigitalOcean droplet does not open port 3306 and NodeJS application cannot connect to outside via this port. 问题是DigitalOcean Droplet没有打开端口3306,NodeJS应用程序无法通过此端口连接到外部。

(P/S: Amazon RDS also opened all ports and anywhere for IP) (P / S:亚马逊RDS还开放所有端口和IP的任何地方)

Please help me, thanks 请帮帮我,谢谢

After Amazon RDS is set up, it only allows connections from my IP address. 设置Amazon RDS后,它只允许来自我的IP地址的连接。

To fix this, go to the Security Group settings and allow connections to RDS from anywhere or just the NodeJS server in question. 要解决此问题,请转到安全组设置,并允许从任何地方或仅与相关的NodeJS服务器连接到RDS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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