create_user.md 1.1 KB
Newer Older
M
Mars Liu 已提交
1 2 3 4 5
# 创建用户

Joe 要给数据组的 John 创建一个用户,他希望John 能够从 `192.168.7.42` 登录 goods 数据库查询数据,
用户第一次登录时使用密码 `goods123`,登录后必须设定一个新密码,那么应该用哪个语句?

M
Mars Liu 已提交
6 7
<hr/>

F
feilong 已提交
8
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill){target="_blank"}。
F
feilong 已提交
9

F
feilong 已提交
10 11
* `show databases;` 列出所有数据库
* `show tables;` 列出所有表
M
Mars Liu 已提交
12

M
Mars Liu 已提交
13 14
## 答案

fix bug  
张志晨 已提交
15
```sql
M
Mars Liu 已提交
16 17 18 19 20 21 22 23 24
create user 'john'@'192.168.7.42' identified by 'goods123' password expire;
grant select on goods.* to 'john'@'192.168.7.42';
flush privileges;
```

## 选项

### A

fix bug  
张志晨 已提交
25
```sql
M
Mars Liu 已提交
26 27 28 29 30 31 32
create user 'john'@'192.168.7.42' identified by 'goods123';
grant select on goods.* to 'john'@'192.168.7.42';
flush privileges;
```

### B

fix bug  
张志晨 已提交
33
```sql
M
Mars Liu 已提交
34 35 36 37 38 39 40
create user 'john'@'192.168.7.42' identified by 'goods123';
grant usage on goods.* to 'john'@'192.168.7.42';
flush privileges;
```

### C

fix bug  
张志晨 已提交
41
```sql
M
Mars Liu 已提交
42 43 44
create user 'john'@'192.168.7.42' identified by 'goods123' on database goods;
flush privileges;
```