【发布时间】:2019-12-15 03:59:49
【问题描述】:
我正在尝试使用通过 AWS Lambda 运行的函数连接到托管在 AWS RDS 上的 MySQL (5.7.22) 数据库,但由于身份验证错误,我无法使用 pymysql 连接到数据库:"Access denied for '<user>'@'<host>' (using password: YES)" .奇怪的是,在我一直用来调试问题的 AWS 实例上,我发现我能够使用与 mysqlclient 相同的参数连接到数据库。
如果相关,我的密码只包含字母数字字符。
这是我使用records 库使用两个包连接到数据库的最小示例(使用裸库会产生相同的结果):
import pymysql
import MySQLdb
config = {} # Dictionary with database credentials.
MySQLdb.connect(
hostname=config['host'],
port=config["port"],
user=config['username'],
passwd=config['password'],
db=config['database'],
connect_timeout=5,
)
# Works fine
pymysql.connect(
hostname=config['host'],
port=config["port"],
user=config['username'],
passwd=config['password'],
db=config['database'],
connect_timeout=5,
)
# raises pymysql.err.OperationalError: (1045, "Access denied for user '<user>'@'<host>' (using password: YES)")
是否存在pymysql 不支持或需要其他选项的数据库配置?
【问题讨论】:
标签: pymysql