是否有任何关于此 PyMysql/Mysql 行为的文档?

Is there any documentation around this PyMysql/Mysql behavior?

这是我用来连接数据库的pymysql代码。我正在使用版本为 Mysql 5.7.22 的 AWS RDS Mysql 实例进行测试。我正在从 https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html

获取证书
pymysql.connect(secret_dict['host'], user=secret_dict['username'],
    passwd=secret_dict['password'], port=port, db=dbname, 
    connect_timeout=5, ssl={'ca': './rds-combined-ca-bundle.pem'})

此代码适用于我的测试数据库,用户启用了 ssl,用户未启用 ssl。 - (通过 ALTER USER 'encrypted_user'@'%' REQUIRE SSL;

我的问题是我在任何 MySQL verison 数据库中看到的这种 pymysql 行为是真实的还是在任何地方记录的?我指的行为是,如果您将 ssl 选项添加到连接调用,它应该工作(成功连接),无论实际用户是否需要 SSL。我不想对每个 Mysql 版本进行测试 :)

从查看 pymysql 代码来看,它所做的似乎是 check if there are any ssl parameters associated with the request, adds it to an ssl map, and then creates a ctx_object from that ssl map and uses that ctx_ object when initializing a socket 数据库。

刚在 Mysql 7 文档中找到这个 guide

"On the server side, the --ssl option specifies that the server permits but does not require encrypted connections. This option is enabled by default, so it need not be specified explicitly."

"By default, MySQL client programs attempt to establish an encrypted connection if the server supports encrypted connections, with further control available through the --ssl-mode option:"

"In the absence of an --ssl-mode option, clients attempt to connect using encryption, falling back to an unencrypted connection if an encrypted connection cannot be established. This is also the behavior with an explicit --ssl-mode=PREFERRED option."

"PREFERRED: Establish an encrypted connection if the server supports encrypted connections, falling back to an unencrypted connection if an encrypted connection cannot be established. This is the default if --ssl-mode is not specified."

所以我相信正在发生的事情是 pymysql 没有指定 ssl-mode 选项,所以使用的 ssl 客户端模式是 PREFERRED,这意味着客户端(pymysql)将尝试建立 ssl 连接(我认为失败是因为用户不需要它)然后回退到未加密的连接,这将是成功的。