不支持身份验证插件"caching_sha2_password"

lch*_*lch 36 python mysql

我试图连接MySQL服务器与python连接器.我创建了一个lcherukuri带有身份验证插件的新用户mysql_native_password.但我得到了错误lcherukuri.有人能帮我吗?

import mysql.connector

cnx = mysql.connector.connect(user='lcherukuri', password='password',
                              host='127.0.0.1',
                              database='test')
cnx.close()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ozg*_*ral 83

我有同样的问题,传递auth_plugin='mysql_native_password'不起作用,因为我不小心安装mysql-connector而不是mysql-connector-python(通过pip3).只是把它留在这里,以防它帮助某人.

  • 谢谢!卸载了 my-connector 并安装了 mysql-connector-python 并且它起作用了! (4认同)
  • 就我而言,这解决了!谢谢! (3认同)
  • 它也解决了我的情况。我关注了 w3schools 并在 pip 和 pip3 上安装了 mysql-connector,但在我写这篇文章时 w3schools 已经过时了。正确的方法是在 pip 和 pip3 上安装 mysql-connector-python。 (2认同)

Ben*_*Ben 38

缓存SHA-2可插入身份验证

在MySQL 8.0中,caching_sha2_password是默认的身份验证插件而不是mysql_native_password.

您正在使用mysql_native_password,这不再是默认设置.您所使用的假设正确的连接器为您的版本,你需要指定auth_plugin参数实例连接对象时

cnx = mysql.connector.connect(user='lcherukuri', password='password',
                              host='127.0.0.1', database='test',
                              auth_plugin='mysql_native_password')
Run Code Online (Sandbox Code Playgroud)

从那些相同的文档:

connect()方法支持auth_plugin可用于强制使用特定插件的参数.例如,如果服务器配置为sha256_password默认使用,并且您要连接到使用身份验证的帐户,请mysql_native_password使用SSL进行连接或指定auth_plugin='mysql_native_password'.


小智 16

这里已经回答了这个问题,并且该解决方案有效。

mysql不支持缓存sha2密码

只需尝试以下命令:

pip install mysql-connector-python
Run Code Online (Sandbox Code Playgroud)

  • 请注意,不推荐使用`mysql-connector`。您应该使用“mysql-connector-python”,如上面的答案所示。 (3认同)

小智 11

我也有类似的错误

  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\authentication.py", line 191, in get_auth_plugin
    "Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
Run Code Online (Sandbox Code Playgroud)

您可能安装了 mysql-connector 而不是 mysql-connector-python。所以你需要为python3再次安装它:

pip3 install mysql-connector-python
Run Code Online (Sandbox Code Playgroud)


小智 10

我遇到了同样的问题,但我的解决方案有所不同,因为这并不完全有效。

我在 GitHub 论坛上找到了这个 - 将其复制并粘贴到您的终端中。您不必更改密码;它可以是完全相同的。

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{NewPassword}';
Run Code Online (Sandbox Code Playgroud)

使用此检查您的设置

select Host,User,plugin from mysql.user;
Run Code Online (Sandbox Code Playgroud)


小智 7

我意识到我安装了 mysql-connector 而不是 mysql-connector-python 所以在终端中运行这些命令

pip3 uninstall mysql-connector
pip3 install mysql-connector-python
Run Code Online (Sandbox Code Playgroud)


小智 6

上述解决方案都不适合我。在观看以下视频之前,我一直感到非常沮丧:https : //www.youtube.com/watch?v=tGinfzlp0fE

pip uninstall mysql-connector 在某些计算机上工作,而在其他计算机上可能不工作。

我做了以下工作:

mysql连接器导致问题。

  1. pip uninstall mysql-connector

    以下可能不需要,但我完全卸下了两个连接器。

  2. pip uninstall mysql-connector-python

    重新安装mysql-conenct-python连接器。

  3. pip install mysql-connector-python


Kau*_*tuv 5

修改Mysql加密

ALTER USER 'lcherukuri'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';


小智 5

pip3 install mysql-connector-python也解决了我的问题。忽略使用 mysql-connector 模块。


小智 5

使用pip install mysql-connector-python

然后像这样连接:

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",               #hostname
  user="Harish",                   # the user who has privilege to the db
  passwd="Harish96",               #password for user
  database="Factdb",               #database name
    auth_plugin = 'mysql_native_password',

)
Run Code Online (Sandbox Code Playgroud)