欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

mysql8出现1045报错+常用的加密plugin汇总

发布时间:2023/12/31 数据库 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 mysql8出现1045报错+常用的加密plugin汇总 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

一些准备工作

/etc/mysql/mysql.conf.d/mysqld.cnf

的[mysqld]下面加入skip-grant-tables

service mysql restart

然后输入mysql就可以登录客户端

 

操作列表

操作

命令

使用备注(必须遵守,否则会碰到相关error)

查询使用的plugin

use mysql;

select user,plugin from user where user='appleyuchi';

更换pluginupdate user set plugin='mysql_native_password' where user='root';
查询授权的/host/user/authentication_stringselect host,user,authentication_string from mysql.user;
删除某个用户drop user appleyuchi@'%'这里的%是上面一句命令中得到的host,也可能是其他域名或者IP
查看某个用户被授予的权限[3]select * from mysql.user where user='appleyuchi'\G; 
设置密码ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'appleyuchi';如果运行不顺利参考[2]解决
新建用户

flush privileges;

create user root@localhost identified by 'appleyuchi';

CREATE USER  'root'@'%' IDENTIFIED BY  'root';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

flush privileges;

由于是skip-grant-tables模式,

所以有时候需要先执行flush privileges

才能继续往下执行其他命令,

所以左侧的flush privileges;执行了两次.

授予权限GRANT ALL PRIVILEGES ON *.* TO 'appleyuchi'@'%' WITH GRANT OPTION; 
查看当前用户所拥有的权限

SHOW GRANTS FOR 'appleyuchi'@'%';

 

select host,user,Grant_priv,Super_priv from mysql.user;

 
刷新权限flush privileges; 
更换密码[5]ALTER USER appleyuchi IDENTIFIED WITH mysql_native_password BY 'appleyuchi'; 

GRANT OPTION指的是把自己的权限赋予其他用户的能力.

all权限≠拥有grant option权限

#####################################################################################################################################

加密用的plugin

plugin名字备注
auth_socket无密码登录
caching_sha2_password[1]中说不支持客户端使用
mysql_native_password推荐使用

#####################################################################################################################################

总结

根据上面的2张表格,

你除了要检查plugin是不是mysql_native_password以外,

还要查看权限,

还要查看是否具有grant option.

缺一不可.

#####################################################################################################################################

错误示范

update mysql.user set authentication_string = "appleyuchi"  where user = "appleyuchi" ;

注意上面的这个绝对是错误的,因为不可能使用明文保存密码

select host,user,authentication_string from mysql.user;

得到结果如下:

 

Reference:

[1]mysql错误:mysql_native_password

[2]mysql8碰到ERROR 1396 (HY000)的解决方案

[3]MySQL 查看用户授予的权限

[4]mysql root权限优化后没有grant权限

[5]mysql8使用grant授权修改

 

 

 

总结

以上是生活随笔为你收集整理的mysql8出现1045报错+常用的加密plugin汇总的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。