【问题标题】:Unable to connect to RDS MySQL from Google App engine SQLAlchemy (unknown host error)无法从 Google App 引擎 SQLAlchemy 连接到 RDS MySQL(未知主机错误)
【发布时间】:2017-08-31 23:06:40
【问题描述】:

我正在尝试从我在 Google App Engine 上运行的 Flask 应用程序连接到 RDS 数据库。我的 SQLAlchemy URI 是

SQLALCHEMY_DATABASE_URI = "mysql+mysqldb://<username>:<password>@******.cet1f6chsyad.us-east-1.rds.amazonaws.com:3306/<dbname>"

我收到以下错误:

super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (_mysql_exceptions.OperationalError) (2005, "Unknown MySQL server host '...' (2)")

如果我尝试使用 Google Cloud Shell 连接到数据库,我可以正确连接。我的以下命令有效:

mysql -u <username> -p -h <url above>

为什么 Python 代码会抛出错误?

【问题讨论】:

  • FWIW,我将驱动程序从 mysqldb 更改为 pymysql 并且它工作正常。

标签: mysql google-app-engine sqlalchemy amazon-rds


【解决方案1】:

使用排序 CName 而不是完整的 RDS URL。

排序Cname:XYZ-RDSNAME.yourdomain.com

而不是

  XYZ-RDSNAME.cet1f6chsyad.us-east-1.rds.amazonaws.com 

( ADD this entry into Route53 )

这是由于 URL 太长,我在从终端和 bash 脚本连接 mysql 时遇到了同样的问题。

【讨论】:

    猜你喜欢
    • 2021-03-20
    • 2017-10-23
    • 2023-04-05
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 2018-05-13
    相关资源
    最近更新 更多