DROP USER

DROP USER 语句用于从 TiDB 系统数据库中删除用户。如果用户不存在,使用关键词 IF EXISTS 可避免出现警告。

语法图

DropUserStmt:

DropUserStmt

Username:

Username

示例

  1. mysql> DROP USER idontexist;
  2. ERROR 1396 (HY000): Operation DROP USER failed for idontexist@%
  3. mysql> DROP USER IF EXISTS idontexist;
  4. Query OK, 0 rows affected (0.01 sec)
  5. mysql> CREATE USER newuser IDENTIFIED BY 'mypassword';
  6. Query OK, 1 row affected (0.02 sec)
  7. mysql> GRANT ALL ON test.* TO 'newuser';
  8. Query OK, 0 rows affected (0.03 sec)
  9. mysql> SHOW GRANTS FOR 'newuser';
  10. +-------------------------------------------------+
  11. | Grants for newuser@% |
  12. +-------------------------------------------------+
  13. | GRANT USAGE ON *.* TO 'newuser'@'%' |
  14. | GRANT ALL PRIVILEGES ON test.* TO 'newuser'@'%' |
  15. +-------------------------------------------------+
  16. 2 rows in set (0.00 sec)
  17. mysql> REVOKE ALL ON test.* FROM 'newuser';
  18. Query OK, 0 rows affected (0.03 sec)
  19. mysql> SHOW GRANTS FOR 'newuser';
  20. +-------------------------------------+
  21. | Grants for newuser@% |
  22. +-------------------------------------+
  23. | GRANT USAGE ON *.* TO 'newuser'@'%' |
  24. +-------------------------------------+
  25. 1 row in set (0.00 sec)
  26. mysql> DROP USER newuser;
  27. Query OK, 0 rows affected (0.14 sec)
  28. mysql> SHOW GRANTS FOR newuser;
  29. ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'

MySQL 兼容性

  • 在 TiDB 中删除不存在的用户时,使用 IF EXISTS 可避免出现警告。Issue #10196

另请参阅