无法使用python pymysql库连接到rds示例

ct3nt3jp  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(255)

我正在尝试使用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/ 有什么我可能错过的潜在设置吗?我仔细检查了其他参数是否匹配。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题