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
Authentication plugin 'caching_sha2_password' is not supported
提问by phani
I am trying to connect to a MySQL server with python connector. I created a new user lcherukuri
with 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()
采纳答案by Ben
Per Caching SHA-2 Pluggable Authentication
In MySQL 8.0,
caching_sha2_password
is the default authentication plugin rather thanmysql_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_plugin
argumentwhen 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 anauth_plugin
argument that can be used to force use of a particular plugin. For example, if the server is configured to usesha256_password
by default and you want to connect to an account that authenticates usingmysql_native_password
, either connect using SSL or specifyauth_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-connector
instead 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
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-connector
work 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 导致问题。
pip uninstall mysql-connector
The following may not need but I removed both connector completely.
pip uninstall mysql-connector-python
re-install mysql-conenct-python connector.
pip install mysql-connector-python
pip uninstall mysql-connector
以下可能不需要,但我完全删除了两个连接器。
pip uninstall mysql-connector-python
重新安装 mysql-conenct-python 连接器。
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 list
and uninstalled all the connectors. In my case they were:
我面临同样的错误 2 天,然后终于找到了解决方案。我使用pip list
并卸载了所有连接器检查了所有已安装的连接器。就我而言,他们是:
- mysql-connector
- mysql-connector-python
- mysql-connector-python-rf
- mysql-连接器
- mysql-connector-python
- mysql-connector-python-rf
Uninstalled them using pip uninstall mysql-connector
and finally downloaded and installed the mysql-connector-python
from MySQL official websiteand it works well.
使用卸载它们pip uninstall mysql-connector
,最后mysql-connector-python
从MySQL官方网站下载并安装了它,并且运行良好。
回答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