MySQL_8.0与5.7区别之账户与安全

Posted 1138720556gary

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL_8.0与5.7区别之账户与安全相关的知识,希望对你有一定的参考价值。

 

 

一、创建用户和用户授权

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

grant all privileges on *.* to Gary@% identified by [email protected]

 

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

  创建用户

create user Gary@% identified by [email protected]; 

 

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

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 [email protected]

 

 

三、密码管理

  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 [email protected];

 

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

select * from mysql.password_history;

 

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

alter user user() identified by [email protected] replace [email protected];

 

 

四、角色管理

  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 [email protected];

 

  将角色授予给用户

grant Gary_role to user1;

 

  显示用户权限

show grants for user1;

 

show grants for user1 using Gary_role;

 

以上是关于MySQL_8.0与5.7区别之账户与安全的主要内容,如果未能解决你的问题,请参考以下文章

MySQL8.0新特性

MySQL8.0有哪些新特性

mysql5.5和5.7的区别

MYSQL02_环境安装5.7插入乱码问题8.0连接失败目录结构总结

迄今最安全的MySQL?细数5.7那些惊艳与鸡肋的新特性(上)转载

MySQL——MySQL 5.7新特性