mysql 8.0.13与5.7的区别_MySQL_8.0与5.7区别之账户与安全

一、创建用户和用户授权

MySQL5.7创建用户和用户授权命令可以同时执行

grant all privileges on *.* to 'Gary'@'%' identified by 'Gary@2019'

MySQL8.0创建用户和用户授权的命令需要分开执行

创建用户

create user 'Gary'@'%' identified by 'Gary@2019';

用户授权【给予所有权限】

grant all privileges on *.* to 'Gary'@'%'

二、认证插件更新

MySQL8.0中默认的身份插件是caching_sha2_password,替代了之前mysql_native_password

通过查看default_authentication_plugin和mysql.user可以查看系统中的变化

show variables like 'default_authentication%'

select user,host,plugin from mysql.user;

也可以把8.0中身份认证插件caching_sha2_password改回原来的mysql_native_password

alter user 'Gary'@'%' identified with mysql_native_password by 'Gary@2020'

三、密码管理

MySQL8.0开始允许限制重复使用以前的密码

使用 show variables like 'password%' 指令可查看对密码管理的限制

password_history = 3 #新密码不能和近期3次内旧密码相同

password_reuse_interval= 90 #新密码不能喝近90天密码相同

password_require_current= ON #修改密码时用户需要提供当前密码

动态修改其中的参数

alter user 'Gary'@'%' password history 5;

可同过修改用户密码语句进行测试

alter user 'Gary'@'%' identified by 'Gary@2019';

可查看用户修改密码历史表

select * from mysql.password_history;

当设置password_require_current = ON,用户修改密码时需要提供当前密码

alter user user() identified by 'Gary@2021' replace 'Gary@2020';

四、角色管理

MySQL8.0提供了角色管理的新功能,角色是一组权限的集合

角色也是一个用户,用角色去模拟用户,可以对角色去进行权限授权

【实践】

创建数据库

create database garydb;

创建数据库表

create table garydb.tl(id int)

创建一个角色【新创建出来的角色无任何权限】

create role 'Gary_role';

给角色授予增、删、改的权限

grant insert,update,delete on garydb.* to 'Gary_role';

创建一个用户

create user 'user1' identified by 'User1@2019';

将角色授予给用户

grant 'Gary_role' to 'user1';

显示用户权限

show grants for 'user1';

show grants for 'user1' using 'Gary_role';

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值