• 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';
    (如需转载学习,请标明出处)
  • 相关阅读:
    Node.js 函数
    Node.js模块系统
    在Apache服务器上安装SSL证书
    Node.js Stream(流)--文件操作
    HTML5自带验证美化
    HTML5约束验证API
    Node.js Buffer(缓冲区)
    Python 练习:简单的购物车(二)
    Python 练习:简单的购物车
    Python 列表操作
  • 原文地址:https://www.cnblogs.com/1138720556Gary/p/11088498.html
Copyright © 2020-2023  润新知