【问题标题】:Does pymysql fully support MySQL authentication?pymysql 是否完全支持 MySQL 身份验证?
【发布时间】: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


    【解决方案1】:

    原来问题是我需要指定一个SSL CA(可以找到here的RDS根证书):

    pymysql.connect(
                hostname=config['host'],
                port=config["port"],
                user=config['username'],
                passwd=config['password'],
                db=config['database'],
                connect_timeout=5,
                ssl={"ca": "./rds-ca-2015-root.pem"},
            )
    

    我不完全确定 MySQLdb 包如何避免这一步。

    【讨论】:

      猜你喜欢
      • 2015-07-04
      • 2020-07-12
      • 2016-05-01
      • 1970-01-01
      • 2020-01-08
      • 2021-01-29
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      相关资源
      最近更新 更多