简体   繁体   English

无法从 EC2 Django 实例连接到 Amazon RDS

[英]Not able to connect to Amazon RDS from EC2 Django Instance

I was deploying my Django Project on AWS (this is my first time doing this) after a lot of first time learning i got stuck at an error:我在 AWS 上部署我的 Django 项目(这是我第一次这样做)经过很多第一次学习后我陷入了一个错误:

django.db.utils.OperationalError: (2005, "Unknown MySQL server host '****.*****.us-east-2.rds.amazonaws.com' (0)") django.db.utils.OperationalError: (2005, "未知的 MySQL 服务器主机 '****.*****.us-east-2.rds.amazonaws.com' (0)")

When i tried migrating my Django Project.I tried multiple solutions but none worked.当我尝试迁移我的 Django 项目时。我尝试了多种解决方案,但都没有奏效。 I tried command mysql -u username -p password -h ****.********.us-east-2.rds.amazonaws.com but this also returned and error.我尝试了命令 mysql -u 用户名 -p 密码 -h ****.********.us-east-2.rds.amazonaws.com 但这也返回了错误。

ERROR 2005 (HY000): Unknown MySQL server host '*****.*********.us-east-2.rds.amazonaws.com' (2)错误 2005 (HY000):未知 MySQL 服务器主机 '*****.*********.us-east-2.rds.amazonaws.com' (2)

UPDATE 2: I Tried using command on AWS Documentation mysql -h mysql–instance1.123456789012.us-east-1.rds.amazonaws.com -P 3306 -u mymasteruser -p which have -h before using -u and -p and an input for Port this changed the error which seems like now the connection is not not able to reach the server which seems a reasonable and a better error than before.更新 2:我尝试在 AWS 文档 mysql -h mysql–instance1.123456789012.us-east-1.rds.amazonaws.com -P 3306 -u mymasterp 和 -p 之前使用 -u 和 -u端口的输入改变了现在似乎连接无法到达服务器的错误,这似乎是一个合理且比以前更好的错误。

ERROR 2003 (HY000): Can't connect to MySQL server on '******.******l2la.us-east-2.rds.amazonaws.com' (10060)错误 2003 (HY000):无法连接到“******.******l2la.us-east-2.rds.amazonaws.com”上的 MySQL 服务器 (10060)

I read in question this about this,they are talking about binding the instance to an IP.How can i do that if that could be the problem?对此有疑问,他们正在谈论将实例绑定到 IP。如果这可能是问题,我该怎么做?

UPDATE1: Screenshots: FIRST RDS INFORMATION UPDATE1:截图:第一个 RDS 信息RDS SS 1 RDS SS 2

EC2 instance Information EC2 实例信息EC2 不锈钢 1 EC2 不锈钢 2

SGs information SGs信息

启动向导 SG If you require any log or information please feel free to ask in the comments.如果您需要任何日志或信息,请随时在评论中提问。 Thanks谢谢

The security group of Database should hold a Value in Inbound Rules:数据库的安全组应在入站规则中保存一个值: SG数据库

This Rule should allow connection from your EC2 Instance.Either set the IP Address or set the SG of EC2 Instance.此规则应允许来自您的 EC2 实例的连接。设置 IP 地址或设置 EC2 实例的 SG。 You can use the Private IP of your instance rather than the Public IP also.您也可以使用实例的私有 IP 而不是公共 IP (Not sure about Security Concerns or Advantages.) (不确定安全问题或优势。)

Update After a Year: Well you should use private IP and not the same security group.DB should only be accessible to the EC2 and not to public.一年后更新:嗯,您应该使用私有 IP 而不是同一个安全组。DB 应该只能被 EC2 访问而不是公共访问。

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

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