mysql 权限
回顾上周
- install mysql
- source
- rpm | dnf
- glibc (二进制)
SQL的语法
- 增
- create databaase | table
- inster
- 删
- delte | drop
- 改
- alter
- update
- 查
- select
- desc
- 增
数据类型
- nmber type
- 整数
- 浮点数
- string type
- char()
- varchar()
- text type
- 文本类型
- json type
- nmber type
表里的某个字段的约束
- not null
- 不可重复
- 自增
- 主键
- 外键
- 索引
权限管理
GRANT语句为MySQL用户帐户和角色分配特权和角色
blog库只允许blog客户端连接,在对这个blog,实现增删改查(权限)
用户管理
- 创建用户
语法: create user ‘用户名’@‘客户端地址|%’ identified by '用户密码'
create user blog@'192.168.212.10' identified by 'password'
create user blog@'192.168.212.%' identified by 'password'
create user blog@'%' identified by 'password'
权限
- SELECT
- INSERT,
- UPDATE,
- DROP,
- DELETE
- CREATE
- ALTER
GRANT语句为MySQL用户帐户和角色分配特权和角色
语法: GRANT [权限] ON [database_name] TO [user@客户端地址]
GRANT ALL ON *.* TO blog@'%';
选项权限:
> SELECT, INSERT, UPDATE, DROP,DELETE,CREATE,ALTER
案例1: 用户dev01对数据库只有select的权限
1. 创建用户
root@localhost [(none)]>create user dev01@'192.168.212.135' identified by 'dev@123';
Query OK, 0 rows affected (0.01 sec)
2. 授权
root@localhost [(none)]>grant select ON *.* TO dev01@'192.168.212.135';
Query OK, 0 rows affected (0.01 sec)
案例1: 用户dev02对数据库只有select, update, create,insetr的权限
1. 创建用户
root@localhost [(none)]>create user dev02@'192.168.212.%' identified by 'dev@123';
Query OK, 0 rows affected (0.01 sec)
2. 授权
root@localhost [(none)]>grant select, update, create, insert ON *.* TO dev02@'192.168.212.%';
Query OK, 0 rows affected (0.01 sec)
- 回收授权(撤销)
语法: REVOKE [权限] ON [db_name] TO [用户]';
root@localhost [(none)]>revoke delete,drop ON *.* From blog@'%';
2.1 案例: 回收权限
root@localhost [(none)]>revoke delete,drop ON *.* From blog@'%';
Query OK, 0 rows affected (0.01 sec)
- 刷新表
FLUSH tables
FLUSH PRIVILEGES #刷新权限
案例:现在需要用户连接数据库blog
grant all on *.* to a@'192.168.212.%' identified by ""