Python 不支持身份验证插件“caching_sha2_password”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50557234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:32:04  来源:igfitidea点击:

Authentication plugin 'caching_sha2_password' is not supported

pythonmysql

提问by phani

I am trying to connect to a MySQL server with python connector. I created a new user lcherukuriwith the authentication plugin mysql_native_password.

我正在尝试使用 python 连接器连接到 MySQL 服务器。我lcherukuri使用身份验证插件创建了一个新用户mysql_native_password

But I got the error

但我得到了错误

mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

mysql.connector.errors.NotSupportedError:不支持身份验证插件“caching_sha2_password”

Can someone help me?

有人能帮我吗?

import mysql.connector

cnx = mysql.connector.connect(user='lcherukuri', password='password',
                              host='127.0.0.1',
                              database='test')
cnx.close()

enter image description here

在此处输入图片说明

采纳答案by Ben

Per Caching SHA-2 Pluggable Authentication

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

In MySQL 8.0, caching_sha2_passwordis the default authentication plugin rather than mysql_native_password.

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

You're using mysql_native_password, which is no longer the default. Assuming you're using the correct connector for your versionyou need to specify the auth_pluginargumentwhen instantiating your connection object

您正在使用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')

From those same docs:

从那些相同的文档:

The connect()method supports an auth_pluginargument that can be used to force use of a particular plugin. For example, if the server is configured to use sha256_passwordby default and you want to connect to an account that authenticates using mysql_native_password, either connect using SSL or specify auth_plugin='mysql_native_password'.

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

回答by ozgeneral

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

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

回答by Anupriya Jaju

This question is already answered here and this solution works.

这个问题已经在这里回答,这个解决方案有效。

caching sha2 password is not supported mysql

mysql 不支持缓存 sha2 密码

Just try this command :

试试这个命令:

pip install mysql-connector-python

回答by Peter Chen

None of the above solution work for me. I tried and very frustrated until I watched the following video: https://www.youtube.com/watch?v=tGinfzlp0fE

以上解决方案都不适合我。我尝试过并且非常沮丧,直到我观看了以下视频:https: //www.youtube.com/watch?v=tGinfzlp0fE

pip uninstall mysql-connectorwork on some computer and it might not work for other computer.

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

I did the followings:

我做了以下事情:

The mysql-connector causes problem.

mysql-connector 导致问题。

  1. pip uninstall mysql-connector

    The following may not need but I removed both connector completely.

  2. pip uninstall mysql-connector-python

    re-install mysql-conenct-python connector.

  3. pip install mysql-connector-python

  1. pip uninstall mysql-connector

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

  2. pip uninstall mysql-connector-python

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

  3. pip install mysql-connector-python

回答by Kaustuv

Modify Mysql encryption

修改Mysql加密

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

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

回答by Kori Vernon

I had this same issue but my resolution was different because this didn't completely work.

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

I found this on a GitHub forum - copy and paste this into your terminal. You don't have to change your password; it can be the exact same.

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

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{NewPassword}';

回答by PacuS

You can go to Settings->Project->Project Interpreter and here install latest version of mysql-connector-python package. In my case it was mysql-connector-python 8.0.15.

您可以转到 Settings->Project->Project Interpreter 并在此处安装最新版本的 mysql-connector-python 包。就我而言,它是 mysql-connector-python 8.0.15。

回答by Pratika S

I was facing the same error for 2 days, then finally I found a solution. I checked for all the installed connectors using pip listand uninstalled all the connectors. In my case they were:

我面临同样的错误 2 天,然后终于找到了解决方案。我使用pip list并卸载了所有连接器检查了所有已安装的连接器。就我而言,他们是:

  1. mysql-connector
  2. mysql-connector-python
  3. mysql-connector-python-rf
  1. mysql-连接器
  2. mysql-connector-python
  3. mysql-connector-python-rf

Uninstalled them using pip uninstall mysql-connectorand finally downloaded and installed the mysql-connector-pythonfrom MySQL official websiteand it works well.

使用卸载它们pip uninstall mysql-connector,最后mysql-connector-pythonMySQL官方网站下载并安装了它,并且运行良好。

回答by FlyingZebra1

To have a more permanent solution without going through your code and modifying whatever needs to be modified: Per MySQL 8 documentation, easiest way to fix this is to add the following to your MySQL d file -> restart MySQL server.

要获得更持久的解决方案,而无需通过您的代码并修改需要修改的任何内容:根据MySQL 8 文档,解决此问题的最简单方法是将以下内容添加到您的 MySQL d 文件 -> 重新启动 MySQL 服务器。

This worked for me!

这对我有用!

If your MySQL installation must serve pre-8.0 clients and you encounter compatibility issues after upgrading to MySQL 8.0 or higher, the simplest way to address those issues and restore pre-8.0 compatibility is to reconfigure the server to revert to the previous default authentication plugin (mysql_native_password). For example, use these lines in the server option file:

如果您的 MySQL 安装必须为 8.0 之前的客户端提供服务,并且您在升级到 MySQL 8.0 或更高版本后遇到兼容性问题,那么解决这些问题并恢复 8.0 之前的兼容性的最简单方法是重新配置服务器以恢复到以前的默认身份验证插件( mysql_native_password)。例如,在服务器选项文件中使用这些行:

[mysqld]
#add the following file to your MySQLd file
    default_authentication_plugin=mysql_native_password

回答by Vishal

Please install below command using command prompt.

请使用命令提示符安装以下命令。

pip install mysql-connector-python

enter image description here

在此处输入图片说明