曲径通幽论坛

标题: 使用 REVOKE 回收权限 [打印本页]

作者: beyes    时间: 2012-4-27 17:28
标题: 使用 REVOKE 回收权限
REVOKE 是 GRANT 的逆操作,它的作用是回收或撤销权限。基本语法为:
[SQL] 纯文本查看 复制代码
REVOKE
    priv_type [(column_list)]
      [, priv_type [(column_list)]] ...
    ON [object_type] priv_level
    FROM user [, user] ...

REVOKE ALL PRIVILEGES, GRANT OPTION
    FROM user [, user] ...

在 《使用 GRANT 进行授权》中演示了 5 中分层的权限设置,REVOKE 也对应于 5 种回收方式。

1. 撤销字段级权限
temp4 用户拥有对  db_temp3 数据库 temp3_tb1 表中的 Name 字段具有 insert 和 select 权限,现在要回收掉 insert 权限,SQL 语句为:
mysql> show grants for 'temp4'@'localhost';
[attach]358[/attach]
mysql> revoke insert(Name) on db_temp3.temp3_tb1 from 'temp4'@'localhost';
Query OK, 0 rows affected (0.00 sec)
再次运行 show grants 命令时可以看到:
[attach]360[/attach]

由上图可见 insert 权限已经被回收。同样也可以使用 temp4 用户登录,然后尝试往 db_temp3.tmep3_tb1 的 Name 里添加一条记录时也会发现错误。

2. 撤销表级权限
类似于上面的字段级撤销,下面演示撤销 temp31 这个用户的 insert, update 和 delete 权限:
[qutoe]mysql> show grants for 'temp31'@'localhost';[/quote]
[attach]362[/attach]
mysql> revoke insert, update, delete on db_temp3.temp3_tb1 from 'temp31'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for 'temp31'@'localhost';
[attach]363[/attach]
由上可见,temp31 用户的 insert,update, delete 的权限。

3. 撤销全局级权限
如果想撤销用户的全部权限,可以采用 REVOKE 的另外一种表示形式,如:
REVOKE ALL PRIVILEGES, GRANT OPTION
    FROM user [, user] ...
例如,beyes 用户具有当前的所有权限:
mysql> show grants for 'beyes'@'localhost';
[attach]364[/attach]
下面将这些权限全部回收:
mysql> revoke all privileges, grant option from 'beyes'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for 'beyes'@'localhost';
[attach]365[/attach]




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2