26
2023
04
17:14:57

【数据库学习】——纠错:mysql Authentication plugin ‘caching_sha2_password‘ is not supported



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

1、环境介绍

Windows

Python3.9

MySQL8.0.29

2、问题描述

在利用Python创建数据池的时候,出现这个问题

代码为:

import mysql.connector.pooling
 
# 定义连接需要的参数,用字典封存,私有参数
__config = {
	"host":"localhost",
	"port":3306,
	"user":"root",
	"password":"root",
	"database":"studentTable"
}

# 创建连接池,定义最大连接数
try:
	pool = mysql.connector.pooling.MySQLConnectionPool(
		**__config,
		pool_size=10
	)
except Exception as e:
	print("创建连接池出现异常:",e)


3、原因分析

使用客户端链接mysql数据库,如果数据库版本高于8.0,可能出现以上问题,因为8.0以前默认使用mysql_native_password身份验证机制,8.0以后默认使用caching_sha2_password方式,因此需要将其改成mysql_native_password验证机制

4、 解决方案

1)方法一:直接改成mysql_native_password验证方式

【数据库bug修复】——Authentication plugin ‘caching_sha2_password‘ is not supported_有情怀的机械男的博客-CSDN博客目录原因连接数据库的时候出现这个问题的解决方法创建数据库连接池时解决方法原因使用客户端链接mysql数据库,如果数据库版本高于8.0,可能出现以上问题,因为8.0以前默认使用mysql_native_password身份验证机制,8.0以后使用caching_sha2_password方式连接数据库的时候出现这个问题的解决方法conn = mysql.connector.connect(host = "localhost", user = "root", pas

https://blog.csdn.net/qq_45769063/article/details/121986314

在参数设置的后面添加这行,修改验证机制

"auth_plugin": 'mysql_native_password'

import mysql.connector.pooling
 
# 定义连接需要的参数,用字典封存,私有参数
__config = {
	"host":"localhost",
	"port":3306,
	"user":"root",
	"password":"root",
	"database":"studentTable",
	"auth_plugin": 'mysql_native_password'
}

# 创建连接池,定义最大连接数
try:
	pool = mysql.connector.pooling.MySQLConnectionPool(
		**__config,
		pool_size=10
	)
except Exception as e:
	print("创建连接池出现异常:",e)

注:这个方案之前是可行的,但是这次没有解决,于是有了方案二

2)方案二: 利用sql命令将验证机制修改

mysql错误:this authentication plugin is not supported_阿冬哥的博客-CSDN博客this authentication plugin is not supported应用程序连接mysql docker一直报错:this authentication plugin is not supported。 google发现,原来是mysql新版本(8.0以上)将root用户使用的plugin更新成caching_sha2_password。 登录mysql输入如下命令可以看...

https://blog.csdn.net/c359719435/article/details/80432508

【纠错】——mysql Authentication plugin ‘caching_sha2_password‘ is not supported问题处理_有情怀的机械男的博客-CSDN博客mysql Authentication plugin ‘caching_sha2_password’ is not supported问题处理使用mysql8.0版本,登录失败,提示 Authentication plugin ‘caching_sha2_password’ is not supported。原因是在MySQL 8.0以后,默认的密码加密方式是caching_sha2_password而不是mysql_native_password。解决方法:1.登录mysql数据库 mys

https://blog.csdn.net/qq_45769063/article/details/122322667

① 打开命令行窗口——cmd

② 登录mysql数据库

mysql -uroot -p

③ 查看不同用户名的身份验证方式select user,plugin from mysql.user;

select user,plugin from mysql.user;

可以看到数据库有5个用户名(user),因为我们创建数据池的时候用的是root用户名,所以我们看一下root用户名的身份验证方式(plugin),root有两个用户名,且有一个验证方式是caching_sha2_password,因此我们需要修改它

④ 将caching_sha2_password修改为mysql_native_password验证方式

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';


再运行select user,plugin from mysql.user;查看不同用户名的身份验证方式,如下图所示,可以发现两个root用户名的验证方式都已经修改成为mysql_native_password了。


⑤ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; 语句解释

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

这行代码有两层含义,第一:修改root的密码为’root’,摒弃原来的旧密码。第二:使用mysql_native_password对新密码进行编码。

注:利用这种方式解决了我的问题

3)方案三 :直接将mysql版本降低为8.0以下

本文链接:https://www.hqyman.cn/post/4005.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: