DROP USER

This statement removes a user from the TiDB system database. The optional keyword IF EXISTS can be used to silence an error if the user does not exist. This statement requires the CREATE USER privilege.

Synopsis

DropUserStmt

DROP USER - 图1

Username

DROP USER - 图2

  1. DropUserStmt ::=
  2. 'DROP' 'USER' ( 'IF' 'EXISTS' )? UsernameList
  3. Username ::=
  4. StringName ('@' StringName | singleAtIdentifier)? | 'CURRENT_USER' OptionalBraces

Examples

  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 compatibility

  • Dropping a user that does not exist with IF EXISTS will not create a warning in TiDB. Issue #10196.

See also