【问题标题】:Connect Python to MySQL DB将 Python 连接到 MySQL 数据库
【发布时间】:2019-09-22 09:36:31
【问题描述】:

由于身份验证插件,无法将我的代码连接到我的 MySQL 数据库

我正在尝试将我的代码连接到新安装的 MySQL 数据库。我知道在 MySQL 8.X 及更高版本上,默认情况下身份验证类型设置为 sha2,并且我读过我需要“强制”一个不同的身份验证插件 (auth_plugin='mysql_native_password')。

嗯...我做到了,但我仍然收到相同的错误消息:

"不支持身份验证插件'{0}'".format(plugin_name)) mysql.connector.errors.NotSupportedError:不支持身份验证插件'caching_sha2_password'

我还应该做什么?

谢谢

import mysql.connector as Sql


myDB = Sql.connect(
    host="localhost",
    user="dbadmin",
    password="myPassword",
    auth_plugin="mysql_native_password"
)


print(myDB)

【问题讨论】:

  • 这是你的情况吗? stackoverflow.com/a/53561512/771848
  • 好吧,与其将 auth_plugin 指定为 mysql_native_password,不如使用 caching_sha2_password,就像错误提示的那样。需要指定它有点奇怪。你有什么连接器版本?

标签: python mysql database


【解决方案1】:

这确实解决了我的问题:

I had the same problem and passing auth_plugin='mysql_native_password' did not work, 
because I accidentally installed mysql-connector instead of mysql-connector-python (via 
pip3). Just to leaving this here in case it helps someone.

Authentication plugin 'caching_sha2_password' is not supported

【讨论】:

    猜你喜欢
    • 2022-01-18
    • 1970-01-01
    • 2018-04-27
    • 2019-07-29
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多