###数据控制语言(DCL)
- 查看授权:
- 格式:`show grants [for 'user'@'host'];`
- 示例:`show grants for 'root'@'localhost';`
- 说明:查看当前登录用户授权时可以不指定用户及主机
- 创建用户:
- 格式:`create user 'user'@'host' identified by 'password';`
- 示例:`create user 'test'@'10.8.156.%' identified by '123456';`
- 说明:%表示通配符,任意的
- 用户授权:
- 格式:`grant 权限 privileges on 库名.表名 to 'user'@'host' identified by 'password';`
- 示例:`grant all privileges on *.* to 'test'@'10.8.156.%' identified by '123456';`
- 说明:权限可以是select、delete、insert、update等,all表示所有权限;*表示所有
- 刷新权限:`flush privileges;`
- 取消授权:
- 格式:`revoke 权限 privileges on 库名.表名 from 'user'@'host';`
- 示例:`revoke delete privileges on test.* from 'test'@'10.8.156.%';`
- 说明:收回当前局域网内的test用户在test库下所有的表的删除权限
- 删除用户:
- 格式:`drop user 'user'@'host';`
- 示例:`drop user 'test'@'10.8.156.%';`
- linux下远程登录:
- `bind-address=127.0.0.1` 改为:`bind-address=0.0.0.0`
- 添加指定用户在指定主机的操作权限:
```mysql
grant all privileges on *.* to 'root'@'%' identified by '123456';
```
### 备份与恢复
- 备份:
- 说明:就是将数据库中的数据(SQL语句)保存到一个文件中
- 示例:`mysqldump -uroot -p test > test.sql`
- 恢复:
- 说明:将保存SQL语句的文件解析,挨个执行其中的SQL语句
- 示例:`mysql -uroot -p test < test.sql`