不支持身份验证插件“caching_sha2_password”
- 2025-03-04 08:25:00
- admin 原创
- 48
问题描述:
我正在尝试使用 python 连接器连接到 MySQL 服务器。我lcherukuri
使用身份验证插件创建了一个新用户mysql_native_password
。
但我收到了错误
mysql.connector.errors.NotSupportedError:不支持身份验证插件“caching_sha2_password”
有人能帮助我吗?
import mysql.connector
cnx = mysql.connector.connect(user='lcherukuri', password='password',
host='127.0.0.1',
database='test')
cnx.close()
解决方案 1:
我遇到了同样的问题,传递auth_plugin='mysql_native_password'
不起作用,因为我不小心安装了mysql-connector
而不是mysql-connector-python
(通过pip3)。 只是把它留在这里,以防它能帮助到别人。
解决方案 2:
每个缓存 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')
来自相同的文档:
该
connect()
方法支持一个auth_plugin
参数,可用于强制使用特定插件。例如,如果服务器默认配置为使用 ,sha256_password
并且您想要连接到使用 进行身份验证的帐户mysql_native_password
,则可以使用 SSL 连接或指定auth_plugin='mysql_native_password'
。
解决方案 3:
这个问题已经在这里得到解答并且这个解决方案有效。
mysql 不支持缓存 sha2 密码
尝试这个命令:
pip install mysql-connector-python
解决方案 4:
上述解决方案对我都不起作用。我尝试过,但非常沮丧,直到我观看了以下视频:
https://www.youtube.com/watch?v =tGinfzlp0fE
pip uninstall mysql-connector
在某些计算机上可以工作,但可能不适用于其他计算机。
我做了以下事情:
mysql-connector 导致问题。
pip uninstall mysql-connector
以下可能不需要,但我完全移除了两个连接器。
pip uninstall mysql-connector-python
重新安装 mysql-conenct-python 连接器。
pip install mysql-connector-python
解决方案 5:
我也遇到了类似的错误
File "C:UsersUserAppDataLocalProgramsPythonPython37-32libsite-packagesmysqlconnectorauthentication.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
您可能安装了 mysql-connector 而不是 mysql-connector-python。因此,您需要为 python3 再次安装它:
pip3 install mysql-connector-python
解决方案 6:
我意识到我安装的是 mysql-connector 而不是 mysql-connector-python,因此在终端中运行这些命令
pip3 uninstall mysql-connector
pip3 install mysql-connector-python
解决方案 7:
我遇到了同样的问题,但我的解决方案不同,因为这并没有完全起作用。
我在 GitHub 论坛上找到了这个 - 将其复制并粘贴到您的终端中。您不必更改密码;它可以完全相同。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{NewPassword}';
使用此检查您的设置
select Host,User,plugin from mysql.user;
解决方案 8:
修改Mysql加密
ALTER USER 'lcherukuri'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
解决方案 9:
使用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',
)
解决方案 10:
对于那些因为首先安装了 mysql-connector 而无法解决问题的人,我做了以下操作:
1.首先在 CMD 上进入“pip”路径
2.使用“pip list”命令
3.将安装三个软件包,分别是 six、protobuf 和 mysql-connector
4.分别卸载它们
5.现在全新安装 mysql-connector-python 模块
这对我来说很有效
解决方案 11:
pip install -U mysql-connector-python
这对我有用,如果你已经安装mysql-connector-python
然后按照https://stackoverflow.com/a/50557297/6202853这个答案
解决方案 12:
您可以转到“设置”->“项目”->“项目解释器”,然后在此处安装最新版本的 mysql-connector-python 包。 在我的情况下,它是 mysql-connector-python 8.0.15。
解决方案 13:
要获得更永久的解决方案,而无需检查代码并修改需要修改的内容:根据MySQL 8 文档,解决此问题的最简单方法是将以下内容添加到 MySQL d 文件中 -> 重新启动 MySQL 服务器。
这对我有用!
如果您的 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
解决方案 14:
我两天来一直遇到同样的错误,最后终于找到了解决方案。我检查了所有已安装的连接器,pip list
然后卸载了所有连接器。在我的情况下,它们是:
mysql 连接器
mysql-连接器-python
mysql-连接器-python-rf
使用后卸载了它们,最后从MySQL 官方网站pip uninstall mysql-connector
下载并安装了,并且运行良好。mysql-connector-python
解决方案 15:
使用以下命令安装 mysql 连接器。
pip install mysql-connector-python-rf
使用命令设置权限。
`ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY
'very_strong_password';
FLUSH PRIVILEGES;`
使用python命令连接mysql数据库
`mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="very_strong_password",
auth_plugin='mysql_native_password')`
解决方案 16:
请使用命令提示符安装以下命令。
pip install mysql-connector-python
解决方案 17:
我尝试解决这个错误,最后安装PyMySQL而不是 mysql 库,并且它可以正常工作。
谢谢。
解决方案 18:
这似乎是 mysql-connector 包的问题。请卸载并安装 mysql-connector-python 包。
sudo pip uninstall mysql-connector
sudo pip install mysql-connector-python
或者,你可以使用带有 auth_plugin 变量的 mysql-connector 包,如以下 Python 代码所示
mysql.connector.connect(host='localhost',port="3306",user='user',password='pass',database='dbname',auth_plugin='myql_native_password')
我认为无论哪种情况,您还需要使用 mysql_native_password 设置 SQL 数据库用户
alter user 'user'@'localhost' identified with mysql_native_password by 'password';
解决方案 19:
如果你正在寻找具有正确插件的连接 URL 或连接字符串;那么以下对我有用
url = 'mysql+mysqlconnector://%s:%s@%s:%s/%s?auth_plugin=mysql_native_password' % (settings['user'], settings['password'], settings['host'], settings['port'], settings['database'])
解决方案 20:
我也遇到了同样的问题。我的问题是,我不小心安装了错误的连接器版本。从文件系统中删除当前安装的版本(我的路径如下:C:\Program Files\Python36\Lib\site-packages),然后执行“pip install mysql-connector-python”。这应该可以解决你的问题
解决方案 21:
如果你正在寻找以下错误的解决方案
错误:由于环境错误而无法安装软件包:[WinError 5] 访问被拒绝:'D:\softwares\spider\Lib\site-packages\libmysql.dll' 请考虑使用该
--user
选项或检查权限。
--user
解决方案:如果发现拒绝访问错误,则应该添加。
pip install --user mysql-connector-python
将此命令粘贴到cmd中并解决您的问题
解决方案 22:
我犯了一个几乎相同的错误:
Error while connecting to MySQL: Authentication plugin 'caching_sha2_password' is not supported
对我来说解决方案很简单:
我的数据库用户名/密码凭据不正确。错误没有描述问题,所以我想我会分享这个,以防其他人遇到这种情况。
解决方案 23:
使用 MySql 8 将我的代码连接到数据库时出现了同样的错误,使用 pip install mysql-connector-python 确实解决了这个错误。
解决方案 24:
这对我来说很有效:
pip install cryptography
解决方案 25:
它因MySQL
服务器版本而失败8.0
,但与版本一起运行5.7.33
解决方案是使用MySQL
版本5.7.33
解决方案 26:
您可以更改 mysql 服务器中的身份验证字符串。
检查所有用户的authentication_string,使用以下查询。
SELECT user,authentication_string,plugin,host FROM mysql.user;
使用 alter query 来更改用户的身份验证字符串。
ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
解决方案 27:
我卸载了 mysql-connector(我按照 w3schools 教程安装了它),然后安装了 mysql-connector-python。它成功了。
解决方案 28:
pip install mysql-connector-python,我希望它能起作用