MySQL新特性-账户与安全

1,用户创建和授权

到了MySQL8中,用户创建与授权语句必须是分开执行,之前版本是可以一起执行。

MySQL8的版本

grant all privileges on *.* to 'lijin'@'%' identified by 'Lijin@2022';

create user 'lijin'@'%' identified by 'Lijin@2022';
grant all privileges on *.* to 'lijin'@'%';

MySQL5.7的版本

grant all privileges on *.* to 'lijin'@'%' identified by 'Lijin@2022';

2,认证插件更新

MySQL 8.0中默认的身份认证插件是caching_sha2_password,替代了之前的mysql_native_password。

show variables like 'default_authentication%';

5.7版本

扫描二维码关注公众号,回复: 15530877 查看本文章

8版本

select user, host,plugin from mysql.user;

这个带来的问题就是如果客户端没有更新,就连接不上!!

当然可以通过在MySQL的服务端找到my.cnf的文件,把相关参数进行修改(不过要MySQL重启后才能生效)

如果没办法重启服务,还有一种动态的方式:

alter user 'lijin'@'%' identified with mysql_native_password by 'Lijin@2022';
select host,user from mysql.user;

使用老的Navicat for MySQL也能访问

3, 密码管理

MySQL 8.0开始允许限制重复使用以前的密码(修改密码时)。

并且还加入了密码的修改管理功能

show variables like 'password%';

修改策略(全局级)

set persist password_history=3;        --修改密码不能和最近3次一致

修改策略(用户级)

alter user 'lijin'@'%' password history 3;
select user, host,Password_reuse_history from mysql.user;

使用重复密码修改用户密码(指定lijin用户)

alter user 'lijin'@'%' identified by 'Lijin@2022';

如果我们把全局的参数改为0,则对于root用户可以反复的修改密码

alter user 'root'@'localhost' identified by '789456';

password_reuse_interval 则是按照天数来限定(不允许重复的)

password_require_current 是否需要校验旧密码(off 不校验、 on校验)(针对非root用户)

set persist password_require_current=on;

猜你喜欢

转载自blog.csdn.net/m0_70299172/article/details/130496151