MySQL AWS:无法从我的机器连接到 RDS 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37212945/
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 21:47:29  来源:igfitidea点击:

AWS: can't connect to RDS database from my machine

mysqldjangodatabaseamazon-web-servicesamazon-rds

提问by Aminah Nuraini

The EC2 instance/live web can connect just fine to the RDS database. But when I want to debug the code in my local machine, I can't connect to the database and got this error:

EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)")

OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pemand .ppkkeys to .sshand I already configure EB CLI. I don't know what should I do anymore.

我已经添加.pem.ppk钥匙.ssh,我已经配置EB CLI。我不知道我该怎么办了。

FYI: The app is in Django

仅供参考:该应用程序在 Django 中

回答by Aminah Nuraini

It turns out it is not that hard. Do these steps:

事实证明,这并不难。执行以下步骤:

  1. Go to EC2 Dashboard
  2. Go to Security Groups tab
  3. Select and only select the RDS database security group. You'll see the security group detail at the bottom
  4. Click Inbound tab
  5. Click Edit button
  6. Add Type:MYSQL/Aurora;Protocol:TCP;Range:3306;Source:0.0.0.0/0
  1. 转到 EC2 仪表板
  2. 转到安全组选项卡
  3. 选择并仅选择 RDS 数据库安全组。您将在底部看到安全组详细信息
  4. 单击入站选项卡
  5. 单击编辑按钮
  6. 添加类型:MYSQL/Aurora;协议:TCP;范围:3306;来源:0.0.0.0/0

Steps

脚步

回答by Anthony R

MAKE SURE PUBLIC ACCESSIBILITYIS SET TO YES

确保PUBLIC ACCESSIBILITY设置为“是”

This is what I spent the last 3 days trying to solve...

这就是我在过去 3 天里试图解决的问题...

Instructions to change Public Accessibility

更改公共可访问性的说明

回答by Slava Fomin II

Make sure that your VPC and subnets are wide enought.

确保您的 VPC 和子网足够宽。

The following CIDR configuration works great for two subnets:

以下 CIDR 配置适用于两个子网:

  • VPC 10.0.0.0/1610.0.0.0 — 10.0.255.255 (65536 addresses)

  • Subnet 1 10.0.0.0/1710.0.0.0 — 10.0.127.255 (32768 addresses, half)

  • Subnet 2 10.0.128.0/1710.0.128.0 — 10.0.255.255 (32768 addresses, other half)

  • 专有网络 10.0.0.0/1610.0.0.0 — 10.0.255.255 (65536 addresses)

  • 子网 1 10.0.0.0/1710.0.0.0 — 10.0.127.255 (32768 addresses, half)

  • 子网 2 10.0.128.0/1710.0.128.0 — 10.0.255.255 (32768 addresses, other half)

Adjust it if you need three subnets.

如果您需要三个子网,请调整它。



I wasn't being able to connect to my RDS database. I've manually reviewed any detail and everything was alright. There were no indications of any issues whatsoever and I couldn't find any suitable information in the documentation. My VPC was configured with narrow CIDR: 10.0.0.0/22 and each subnet had a 255 addresses. After I've changed CIDR to 10.0.0.0/16 and split it totally between two subnets my RDS connection started to working. It was a pure luck that I've managed to find a source of the problem, because it doesn't make any sense to me.

我无法连接到我的 RDS 数据库。我已经手动检查了所有细节,一切都很好。没有任何问题的迹象,我在文档中找不到任何合适的信息。我的 VPC 配置了窄 CIDR:10.0.0.0/22,每个子网有 255 个地址。在我将 CIDR 更改为 10.0.0.0/16 并将其完全拆分到两个子网后,我的 RDS 连接开始工作。我设法找到问题的根源纯粹是运气,因为它对我来说没有任何意义。

回答by y3sh

Just burned two hours going through the great solutions on this page. Time for the stupid answer!

刚刚花了两个小时浏览此页面上的出色解决方案。是时候给出愚蠢的答案了!

I redid my Security Groups, VPC's, Routing Tables, Subnets, Gateways... NOPE. I copy-pasted the URL from the AWS Console, which in some cases results in a hidden trailing space. The endpoint is in a <div>element, which the browser gives a \nwhen copying. Pasting this into the Intellij db connector coerces it to a space.

我重做了我的安全组、VPC、路由表、子网、网关......不。我从 AWS 控制台复制粘贴了 URL,这在某些情况下会导致隐藏的尾随空格。端点位于一个<div>元素中,浏览器\n在复制时会给出一个元素。将其粘贴到 Intellij db 连接器会将其强制为一个空格。

I only noticed the problem after pasting the URL into a quote string in my source code.

我只是在将 URL 粘贴到我的源代码中的引号字符串中后才注意到这个问题。

hidden space

隐藏空间

hidden space in IDE

IDE 中的隐藏空间

回答by Shengfeng Li

In my case, when I upgrade the size. The private address of the rds instance fell into a private subnet of the VPC. You can use the articleMy instance is in a private subnet, and I can't connect to it from my local computerto find out your db instance address.

就我而言,当我升级尺寸时。rds 实例的私有地址落入了 VPC 的私有子网。您可以使用文章我的实例位于私有子网中,我无法从本地计算机连接到它来查找您的数据库实例地址。

However, changing the route table didn't fix my issue. What I did finally solve my problem is to downgrade the size and then upgrade the size back. Once the private address falls back to the public subnet. Everything works like a charm.

但是,更改路由表并没有解决我的问题。我最终解决的问题是降级大小,然后再升级大小。一旦私有地址回退到公共子网。一切都像一个魅力。