25
2023
04
10:49:39

error 2059: Authentication plugin ‘caching_sha2_password‘ cannot be loaded: /usr/lib64/mysql/plugin/

报错内容


483ea6ff05bde5209a3d53f77131e9d9_686fa3f9fd1141a6b935f7737690b509.png

error 2059: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory


操作内容

想要实现mysql的远程登录

我的尝试,从虚拟机登录到本地mysql


解决方法(针对mysql8.0后的版本)

方法一:

修改密码的加密方式,对后续的新建用户有效(在添加下述语句后,后续的新用户加密方式默认被改为了mysql_native_password),而前期的老用户默认密码加密方式还是(caching_sha2_password)

找到my.ini文件,在[mysqld]下添加


default_authentication_plugin=mysql_native_password


保存,重启mysql服务,重启mysql服务,重启mysql服务!!!!生效。

9482a8f5600b6f65b9ce2873f7c771cf_bd39b4ce48c94b21909803ecf135e7a8.png


老用户需要手动修改为mysql_native_password


ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; #更新一下用户的密码

FLUSH PRIVILEGES; #刷新权限


方法二:

没有所谓的方法二,就跟上面的一样。不过是,创建一个新用户,指定加密方式,赋予所有权限,用新用户连接mysql(哈哈)


-- 创建用户名为hyl,设所有ip均可登录,密码root

create user hyl@'%' identified WITH mysql_native_password BY 'root';

-- grant给hyl赋予所有的库和表的权限。

grant all privileges on *.* to hyl@'%' with grant option;

-- 刷新

flush privileges;


错误原因

新版本的MySQL新特性导致,导致认证方式有问题。


MySQL8.0版本默认的认证方式是caching_sha2_password


f2156f48d8c087bcb060f5dbce91924f_e9d01055783a46febaab78538ff7dd41.png

而在MySQL5.7版本则为mysql_native_password

b8eaf9be7d746be7a736bc0a12a666fe_3cf8f9f9203e4507b596a9c33347e27b.png


学到的知识

创建新用户: 其中username为自定义的用户名;host为登录域名,host为’%'时表示为 任意IP,为localhost时表示本机,或者填写指定的IP地址;paasword为密码


create user 'username'@'host' identified by 'password'; 


为用户授权: 其中*.第一个表示所有数据库,第二个表示所有数据表,如果只是部分授权那就把对应的写成相应数据库或者数据表;username为指定的用户;%为该用户登录的域名


grant 权限 on . to ‘username’@‘%’

grant 权限 on . to ‘username’@‘%’ identified by “密码”


grant all privileges on *.* to 'username'@'%' with grant option; 


*.*第一个 * 表示所有数据库,第二个 * 表示所有数据表

privileges(权限列表),可以是all priveleges, 表示所有权限,也可以是select、update等权限,多个权限的名词,相互之间用逗号分开。

on用来指定权限针对哪些库和表。

to 表示将权限赋予某个用户,@后面接限制的主机,可以是IP,IP段,域名以及%,%表示任何地方。

注意:这里%有的版本不包括本地,以前碰到过给某个用户设置了%允许任何地方登录,但是在本地登录不了,这个和版本有关系,遇到这个问题再加一个localhost的用户就可以了。

WITH GRANT OPTION 这个选项表示该用户可以将自己拥有的权限授权给别人。

举例:


用户名:ad,密码:ad_pass,登陆ip:192.168.0.10

//用户在所有登陆ip的权限

grant all on *.* to 'ad'@'%' identified by "ad_pass";

  

//开放管理MySQL中所有数据库的权限

grant all on *.* to 'ad'@'192.168.0.10' identified by "ad_pass";


//开放管理MySQL中具体数据库(test)的权限

grant all privileges on test to 'ad'@'192.168.0.10' identified by "ad_pass";


//开放管理MySQL中具体数据库中的表(test.table1)的权限

grant all on test.table1 to 'ad'@'192.168.0.10' identified by "ad_pass"


//开放管理MySQL中具体数据库的表(test.table1)的部分列的权限

grant select(id,se,rank) on test.table1 to 'ad'@'192.168.0.10' identified by "ad_pass";


//开放管理操作指令

grant select,insert,update,delete on test.* to 'ad'@'192.168.0.10' identified by "ad_pass";



权限的收回


#收回权限(不包含赋权权限)

REVOKE ALL PRIVILEGES ON *.* FROM 'username'@'%';

#收回赋权权限

REVOKE GRANT OPTION ON *.* FROM 'username'@'%';


#操作完后重新刷新权限

flush privileges;


结果测试(用户‘ll’测试)

老用户采用默认的caching_sha2_password (登录失败)

054825f377c3331a286ae86ac77a9d32_9529574351f144559ec1868852abd244.png

d65cedcabb76fdaa43f7363a7fa8b714_d68341bd1de2468fa7dcfdc65b4e0d96.png



修改 ‘ll’ 的加密方式为 mysql_native_password


ALTER USER 'll'@'%' IDENTIFIED WITH mysql_native_password BY 'root'; 

在这里插入图片描述在这里插入图片描述




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

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

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

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

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: