Does pymysql fully support MySQL authentication?

半城伤御伤魂 提交于 2020-03-25 22:01:33

问题


I am trying to connect to a MySQL (5.7.22) database hosted on AWS RDS using a function run through AWS Lambda, but am unable to connect to the database using pymysql due to an authentication error: "Access denied for '<user>'@'<host>' (using password: YES)". Curiously, on an AWS instance that I've been using to debug the issue, I find that I am able to connect to the database using the same parameters with mysqlclient.

In case it's relevant, my password only contains alphanumeric characters.

Here is a minimal example I've used to connect to the database with the two packages using the records library (using bare libraries yields the same results):

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)")

Are there database configurations that are not supported by pymysql or require additional options?


回答1:


It turns out that the problem was that I needed to specify an SSL CA (the RDS root certificate that can be found here):

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"},
        )

I'm not entirely sure how the MySQLdb package avoids this step.



来源:https://stackoverflow.com/questions/59331500/does-pymysql-fully-support-mysql-authentication

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!