mysql的三大组件(详解MySQL8的新特性ROLE)
mysql的三大组件
详解MySQL8的新特性ROLE【MySQL的ROLE解决了什么问题】
假设你是一个职业素养良好的DBA比较同时又比较注重权限管理的话;可能遇到过这样的问题,数据库中有多个开发人员的账号;有一天要建
一个新的schema,如果你希望之前所有的账号都能操作这个schema下的表的话,在mysql-8.0之前你要对第一个账号都单独的赋一次权。
mysql-8.0.x所权限抽象了出来用ROLE来表示,当你为ROLE增加新的权限的时候,与这个ROLE关联的所有用户的权限也就一并变化了;针对
上面提到的场景在mysql-8.0.x下只要一条SQL就解决了。
【机智的MySQL开发】
MySQL引进ROLE用了一个非常机智的做法,既然ROLE是一堆权限的象征,这东西在MySQL里面本来就有呀!它就是USER呀。
1): 创建角色
|
create role devgroup; |
查看mysql.user表真会被MySQL的机智给吓到
|
select user ,host from mysql. user ; + ------------------+-----------+ | user | host | + ------------------+-----------+ | devgroup | % | | backup | 127.0.0.1 | | mysql.sys | localhost | | root | localhost | + ------------------+-----------+ |
说好的role事实上只是一个user呀!
2): 给角色赋权
|
grant all on tempdb.* to devgroup; Query OK, 0 rows affected (0.07 sec) |
和操作用户比起来是一样一样的!
3):创建用户并把角色的权限赋给它
|
create user tom@ '127.0.0.1' identified by '123456' ; Query OK, 0 rows affected (0.09 sec) grant devgroup to tom@ '127.0.0.1' ; Query OK, 0 rows affected (0.09 sec) |
4):测试刚创建的用户是否可以登录
|
mysql -h127.0.0.1 -P3306 -utom -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and / or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and / or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show grants; + -------------------------------------------+ | Grants for tom@127.0.0.1 | + -------------------------------------------+ | GRANT USAGE ON *.* TO `tom`@`127.0.0.1` | | GRANT `devgroup`@`%` TO `tom`@`127.0.0.1` | + -------------------------------------------+ 2 rows in set (0.00 sec) |
【角色和用户只是一个硬币的两面】
如果你还是觉得“角色”和“用户”是两个不一样的东西、那我只能是出大招了
1): root@127.0.0.1 用户当成角色赋给刚才的tom用户
|
grant root@ '127.0.0.1' to tom@ '127.0.0.1' ; Query OK, 0 rows affected (0.04 sec) |
2):用户tom用户检察一下自己的权限
|
show grants; + --------------------------------------------------------------+ | Grants for tom@127.0.0.1 | + --------------------------------------------------------------+ | GRANT USAGE ON *.* TO `tom`@`127.0.0.1` | | GRANT `devgroup`@`%`,`root`@`127.0.0.1` TO `tom`@`127.0.0.1` | + --------------------------------------------------------------+ 2 rows in set (0.00 sec) |
可以看到root@127.0.0.1的权限已经被套上去了、既然都是root用户的权限了我们来删除一个tempdb库看一下吧!
3): 删库
|
drop database tempdb; ERROR 1044 (42000): Access denied for user 'tom' @ '127.0.0.1' to database 'tempdb' |
看起来没有权限删除这个库呀!事实上是MySQL-8默认并不会激活role,关于是否激活role是由activate_all_roles_on_login这个参数控制的
4): 开启activate_all_roles_on_login
|
set @@ global .activate_all_roles_on_login=1; Query OK, 0 rows affected (0.00 sec) |
5): 重新登录一次tom再试着删除一下tempdb库
|
mysql -h127.0.0.1 -P3306 -utom -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and / or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and / or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use tempdb; Database changed mysql> show databases; + --------------------+ | Database | + --------------------+ | information_schema | | mysql | | performance_schema | | sys | | tempdb | + --------------------+ 5 rows in set (0.01 sec) mysql> drop database tempdb; Query OK, 0 rows affected (0.09 sec) |
以上就是详解MySQL8的新特性ROLE的详细内容,更多关于MySQL8 新特性ROLE的资料请关注开心学习网其它相关文章!
原文链接:https://www.cnblogs.com/JiangLe/p/9851958.html
- docker怎么创建mysql服务(Docker部署MySQL8集群一主二从的实现步骤)
- win10安装mysql8.0如何启动(win10下mysql 8.0.23 安装配置方法图文教程)
- mysql8.0.16安装步骤图解(mysql 8.0.22 安装配置图文教程)
- mysql8.0.15安装详细教程(Mysql8.0.22解压版安装教程小白专用)
- idea安装mybatis(IDEA使用mybatis-generator及配上mysql8.0.3版本遇到的bug)
- mysql8.0安装版安装详细教程(mysql 8.0.24版本安装配置方法图文教程)
- mysql8.0.25安装及配置超详细教程(MySQL8.0.21安装步骤及出现问题解决方案)
- mysql的默认数据库例子在哪里(修改MySQL8.0 默认的数据目录快捷操作无配置)
- mybatis为什么还用mysql(关于MyBatis连接MySql8.0版本的配置问题)
- mysql8.0.15安装详细教程(mysql8.0.11数据目录迁移的实现)
- mysql 分片键规则(MySql8 WITH RECURSIVE递归查询父子集的方法)
- linux安装nacos教程(Nacos配置MySQL8的方法)
- windows下mysql密码重置(Windows10系统下Mysql8.0.13忘记root密码的操作方法)
- mysql8.0详解(MySQL 8.0 的 5 个新特性,太实用了!)
- redhat6.5安装mysql(Redhat7.3安装MySQL8.0.22的详细教程二进制安装)
- docker怎样安装mysql8(docker-compose安装db2数据库操作)
- 梁山创始人杜迁,为何不受宋江待见,只排名83位(梁山创始人杜迁)
- 法国面包(法国面包法棍)
- 微信(微信分身)
- 双十二(双十二和双十一哪个划算)
- 佛肚竹盆景的养护之道(佛肚竹盆景的养护之道)
- 包水饺(包水饺手法怎么包视频)
热门推荐
- vue3.0安装element(vue3+electron12+dll开发客户端配置详解)
- 服务器使用docker(使用ssh连接docker服务器的方法)
- sed命令删除某行(如何利用sed命令高效删除文件的特定行)
- MongoDB的where查询
- jquery导航栏动画(jQuery实现带展开动画的导航栏效果)
- mysql查询很慢怎么回事(MySQL Like模糊查询速度太慢如何解决)
- python教程列表排序(Python一行代码实现快速排序的方法)
- python数值基本运算方法(Python常见数字运算操作实例小结)
- css居中代码(CSS之居中布局的实现方法)
- vscode报错提示框(关于在vscode使用webpack指令显示"因为在此系统中禁止运行脚本"问题)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9