将Python连接到MySQL DB

时间:2019-05-03 20:18:18

标签: python mysql database

由于身份验证插件,无法将我的代码连接到我的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)

1 个答案:

答案 0 :(得分:0)

这确实解决了我的问题:

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