一、授权格式:
grant 权限 on 数据库对象 to 用户 [identified by '密码']
> 权限可以是all, select, insert, update, delete、
> references 外键、index索引
> create view、show view
> 存储过程 函数 create routine、alter routine、execute
>
> 密码要用 单/双引号 括起来
> 例如:grant all on *.* to slave@192.168.0.10 identified by 'funsion';
> 用户可以是 test@192.168.1.9, % 代表给所有IP开放权限
>
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
> grant 普通 DBA 管理某个 MySQL 数据库的权限。 关键字 privileges 可以省略。
grant all privileges on testdb to dba@'localhost'
给账号表授权
grant all on *.* to dba@localhost;
二、MySQL grant 权限,分别可以作用在多个层次上。
- grant 作用在整个 MySQL 服务器上:
grant select on *.* to dba@localhost;
> dba 可以查询 MySQL 中所有数据库中的表。
>
grant all on *.* to dba@localhost;
> dba 可以管理 MySQL 中的所有数据库
- grant 作用在单个数据库上:
复制代码代码如下:
grant select on testdb.* to dba@localhost;
> dba 可以查询 testdb 中的表。
- grant 作用在单个数据表上:
grant select, insert, update, delete on testdb.orders to dba@localhost;
三、 查看 MySQL 用户权限
查看当前用户(自己)权限:
show grants;
查看其他 MySQL 用户权限:
show grants for dba@localhost;
四、撤销已经赋予给 MySQL 用户权限的权限。
revoke 跟 grant 的语法差不多,只需要把关键字 to 换成 from 即可:
grant all on *.* to dba@localhost;
revoke all on *.* from dba@localhost;