无法使用Python pymysql库连接到RDS实例

时间:2018-10-09 16:52:04

标签: python mysql amazon-web-services amazon-rds pymysql

我正在尝试使用Python的pymysql库连接到RDS实例。不幸的是,我又回来了一个异常。

这是我的Python代码:

import pymysql

#Connect
connection = pymysql.connect(host='jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/dbname',
                             port='3306',
                             user='username',
                             password='pass',
                             database='dbname')

执行它时,我收到以下异常:

Traceback (most recent call last):
  File "/path/to/file/test.py", line 8, in <module>
    database='treemigodb')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 327, in __init__
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 629, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/dbname' ([Errno 8] nodename nor servname provided, or not known)")

这是我尝试过的:

  • 我已经在AWS端打开了安全组以进行通信。我以前曾在Java中成功执行过此连接。 AWS已按原样进行配置。
  • 在其他示例中,我看到host格式倾向于变化。因此,我尝试了: jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/dbname

    jdbc:mysql://url.us-east-1.rds.amazonaws.com/dbname

    jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/

    jdbc:mysql://url.us-east-1.rds.amazonaws.com/

    dbname.url.us-east-1.rds.amazonaws.com/dbname

    url.us-east-1.rds.amazonaws.com/dbname

    dbname.url.us-east-1.rds.amazonaws.com/

是否存在一些可能会丢失的潜在设置?我已经仔细检查了所有其他参数是否匹配。

0 个答案:

没有答案