无法连接到 AWS RDS 上的 mysql(错误 2003)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24705465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:43:40  来源:igfitidea点击:

can't connect to mysql on AWS RDS (error 2003)

mysqlamazon-web-servicesamazon-ec2amazon-rds

提问by user3175226

I'm in trouble on setting up a MySQL RDS.

我在设置 MySQL RDS 时遇到了麻烦。

From my EC2instance I can connect fine, but from my laptopI get error 2003 (timeout).

我的 EC2实例我可以正常连接,但从我的笔记本电脑我收到错误 2003(超时)。

  • My RDS instance is configured to be publicly accessible.
  • My security group hasa rule inbound and outbound to allow all traffic everywhere (0.0.0.0/0).
  • 我的 RDS 实例配置为可公开访问。
  • 我的安全组一个入站和出站规则,允许所有流量无处不在 (0.0.0.0/0)。

Should I configure something on my VPC or Internet Gateway?

我应该在我的 VPC 或 Internet 网关上配置一些东西吗?

采纳答案by Matt Caton

As your security groups are wide open, my guess is that your LAN is blocking outbound traffic on port 3306. Infact, looking at this support page ( http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html) firewall issues are listed as number 2 in common reasons for being unable to connect.

由于您的安全组是完全开放的,我的猜测是您的 LAN 正在阻止端口 3306 上的出站流量。事实上,查看此支持页面 ( http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance。 html) 防火墙问题在无法连接的常见原因中列为第 2 位。

This question may help you out: MySql networking issue. May be worth taking a look at your local firewall settings. You mention you are on a laptop so my guess is your current network is classed as a public network and your outbound ports are being blocked (as mentioned in the question Ive linked).

这个问题可以帮到你:MySql 网络问题。可能值得查看您的本地防火墙设置。您提到您使用的是笔记本电脑,所以我的猜测是您当前的网络被归类为公共网络,并且您的出站端口被阻止(如 Ive 链接的问题中所述)。

If that gets you nowhere, its worth telnetting to your RDS instance on port 3306 and seeing what happens. This may well give you some more debug information which could help with the general Googling around of the issue.

如果这让你无处可去,值得在端口 3306 上 telnet 到你的 RDS 实例,看看会发生什么。这很可能会为您提供更多调试信息,这些信息可以帮助您在谷歌上搜索该问题。

As an aside, personally I wouldn't open up an RDS instance to the Internet directly. Its reasonably straight forward to setup an ssh tunnel to forward traffic to your RDS instance through an SSH server. Something like the stuff shown here: http://www.techrepublic.com/blog/linux-and-open-source/tips-and-tricks-to-help-you-do-more-with-openssh/

顺便说一句,我个人不会直接向 Internet 开放 RDS 实例。设置 ssh 隧道以通过 SSH 服务器将流量转发到您的 RDS 实例是相当直接的。像这里显示的东西:http: //www.techrepublic.com/blog/linux-and-open-source/tips-and-tricks-to-help-you-do-more-with-openssh/

UPDATE: I've never used RDS with the 'publicly available' option (all our setups used ssh tunnelling to private RDS instances). Googling around, I came across quite a few queries in the AWS forums relating to access issues to public RDS instances. For example, https://forums.aws.amazon.com/thread.jspa?threadID=123483. May be worth trying the suggested fix of explicitly creating entries in the route table for the subnets that compose the RDS instance?

更新:我从未将 RDS 与“公开可用”选项一起使用(我们所有的设置都使用 ssh 隧道连接到私有 RDS 实例)。通过谷歌搜索,我在 AWS 论坛中遇到了很多与公共 RDS 实例的访问问题相关的问题。例如,https://forums.aws.amazon.com/thread.jspa?threadID=123483。是否值得尝试在路由表中为组成 RDS 实例的子网显式创建条目的建议修复?

回答by Nadeem Ahmed

Check your sub net group I had same issue with my RDS instance then I identify that in my sub net group I had 4 sub nets from which 2 are private and RDS when pick private it cause connectivity issue. Then I create one more sub net group with public sub nets and attach to my RDS instance and connect successfully.

检查您的子网组 我的 RDS 实例遇到了同样的问题,然后我发现在我的子网组中有 4 个子网,其中 2 个是私有的,而 RDS 在选择私有时会导致连接问题。然后我再创建一个带有公共子网的子网组并附加到我的 RDS 实例并成功连接。

回答by yvesva

If the accepted answer doesn't work, ensure your IP address is available as an option in the Route Table of the DB's connected VPC.

如果接受的答案不起作用,请确保您的 IP 地址可用作数据库连接的 VPC 的路由表中的一个选项。

This can be accessed:

这可以访问:

database > associated subnet > route table

数据库 > 关联子网 > 路由表