role.md 835 字节
Newer Older
M
Mars Liu 已提交
1 2
# 角色

M
having  
Mars Liu 已提交
3
Joe 现在是团队的 DBA,公司数据分析组有 Fred、Alice、James、Jone 四位成员,现在Joe需要给数据分析组授权,允许他们
M
Mars Liu 已提交
4
查询 MySQL 8 服务器 goods 数据库中的所有表,*规范*的操作应该是
M
Mars Liu 已提交
5 6 7

## 答案

M
having  
Mars Liu 已提交
8
```mysql
M
Mars Liu 已提交
9 10
create role analysis;
grant analysis to fred, alice, james, jone;
M
having  
Mars Liu 已提交
11 12
grant select on  goods.* to analysis;
flush privileges;
M
Mars Liu 已提交
13 14 15 16 17 18
```

## 选项

### 将来人员变动管理会很繁琐

M
having  
Mars Liu 已提交
19 20
```mysql
grant select on goods.* to fred, alice, james, jone;
M
Mars Liu 已提交
21 22
```

M
having  
Mars Liu 已提交
23
### 错误的语法
M
Mars Liu 已提交
24

M
having  
Mars Liu 已提交
25
```mysql
M
Mars Liu 已提交
26 27
create role analysis;
grant analysis to fred, alice, james, jone;
M
having  
Mars Liu 已提交
28 29
grant all on all tables in schema goods to analysis;
flush privileges;
M
Mars Liu 已提交
30 31
```

M
having  
Mars Liu 已提交
32
### 过度授权
M
Mars Liu 已提交
33

M
having  
Mars Liu 已提交
34
```mysql
M
Mars Liu 已提交
35 36
create role analysis;
grant analysis to fred, alice, james, jone;
M
having  
Mars Liu 已提交
37 38
grant select on *.* to analysis;
flush privileges ;
M
Mars Liu 已提交
39
```