REVOKE <privileges>

REVOKE <privileges> 语句用于删除已有用户的权限。执行 REVOKE <privileges> 语句需要拥有分配的权限,并且拥有 GRANT OPTION 权限。

语法图

  1. GrantStmt ::=
  2. 'GRANT' PrivElemList 'ON' ObjectType PrivLevel 'TO' UserSpecList RequireClauseOpt WithGrantOptionOpt
  3. PrivElemList ::=
  4. PrivElem ( ',' PrivElem )*
  5. PrivElem ::=
  6. PrivType ( '(' ColumnNameList ')' )?
  7. PrivType ::=
  8. 'ALL' 'PRIVILEGES'?
  9. | 'ALTER' 'ROUTINE'?
  10. | 'CREATE' ( 'USER' | 'TEMPORARY' 'TABLES' | 'VIEW' | 'ROLE' | 'ROUTINE' )?
  11. | 'TRIGGER'
  12. | 'DELETE'
  13. | 'DROP' 'ROLE'?
  14. | 'PROCESS'
  15. | 'EXECUTE'
  16. | 'INDEX'
  17. | 'INSERT'
  18. | 'SELECT'
  19. | 'SUPER'
  20. | 'SHOW' ( 'DATABASES' | 'VIEW' )
  21. | 'UPDATE'
  22. | 'GRANT' 'OPTION'
  23. | 'REFERENCES'
  24. | 'REPLICATION' ( 'SLAVE' | 'CLIENT' )
  25. | 'USAGE'
  26. | 'RELOAD'
  27. | 'FILE'
  28. | 'CONFIG'
  29. | 'LOCK' 'TABLES'
  30. | 'EVENT'
  31. | 'SHUTDOWN'
  32. ObjectType ::=
  33. 'TABLE'?
  34. PrivLevel ::=
  35. '*' ( '.' '*' )?
  36. | Identifier ( '.' ( '*' | Identifier ) )?
  37. UserSpecList ::=
  38. UserSpec ( ',' UserSpec )*

示例

  1. CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
  1. Query OK, 1 row affected (0.02 sec)
  1. GRANT ALL ON test.* TO 'newuser';
  1. Query OK, 0 rows affected (0.03 sec)
  1. SHOW GRANTS FOR 'newuser';
  1. +-------------------------------------------------+
  2. | Grants for newuser@% |
  3. +-------------------------------------------------+
  4. | GRANT USAGE ON *.* TO 'newuser'@'%' |
  5. | GRANT ALL PRIVILEGES ON test.* TO 'newuser'@'%' |
  6. +-------------------------------------------------+
  7. 2 rows in set (0.00 sec)
  1. REVOKE ALL ON test.* FROM 'newuser';
  1. Query OK, 0 rows affected (0.03 sec)
  1. SHOW GRANTS FOR 'newuser';
  1. +-------------------------------------+
  2. | Grants for newuser@% |
  3. +-------------------------------------+
  4. | GRANT USAGE ON *.* TO 'newuser'@'%' |
  5. +-------------------------------------+
  6. 1 row in set (0.00 sec)
  1. DROP USER 'newuser';
  1. Query OK, 0 rows affected (0.14 sec)
  1. SHOW GRANTS FOR 'newuser';
  1. ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'

MySQL 兼容性

REVOKE <privileges> 语句与 MySQL 完全兼容。如发现任何兼容性差异,请在 GitHub 上提交 issue

另请参阅