/sql-statements/sql-statement-drop-user.md

https://github.com/pingcap/docs · Markdown · 73 lines · 52 code · 21 blank · 0 comment · 0 complexity · 404f9a7b0358335f16375fae7465b1df MD5 · raw file

  1. ---
  2. title: DROP USER | TiDB SQL Statement Reference
  3. summary: An overview of the usage of DROP USER for the TiDB database.
  4. aliases: ['/docs/dev/sql-statements/sql-statement-drop-user/','/docs/dev/reference/sql/statements/drop-user/']
  5. ---
  6. # DROP USER
  7. 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.
  8. This statement requires the `CREATE USER` privilege.
  9. ## Synopsis
  10. **DropUserStmt:**
  11. ![DropUserStmt](/media/sqlgram/DropUserStmt.png)
  12. **Username:**
  13. ![Username](/media/sqlgram/Username.png)
  14. ## Examples
  15. ```sql
  16. mysql> DROP USER idontexist;
  17. ERROR 1396 (HY000): Operation DROP USER failed for idontexist@%
  18. mysql> DROP USER IF EXISTS 'idontexist';
  19. Query OK, 0 rows affected (0.01 sec)
  20. mysql> CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
  21. Query OK, 1 row affected (0.02 sec)
  22. mysql> GRANT ALL ON test.* TO 'newuser';
  23. Query OK, 0 rows affected (0.03 sec)
  24. mysql> SHOW GRANTS FOR 'newuser';
  25. +-------------------------------------------------+
  26. | Grants for newuser@% |
  27. +-------------------------------------------------+
  28. | GRANT USAGE ON *.* TO 'newuser'@'%' |
  29. | GRANT ALL PRIVILEGES ON test.* TO 'newuser'@'%' |
  30. +-------------------------------------------------+
  31. 2 rows in set (0.00 sec)
  32. mysql> REVOKE ALL ON test.* FROM 'newuser';
  33. Query OK, 0 rows affected (0.03 sec)
  34. mysql> SHOW GRANTS FOR 'newuser';
  35. +-------------------------------------+
  36. | Grants for newuser@% |
  37. +-------------------------------------+
  38. | GRANT USAGE ON *.* TO 'newuser'@'%' |
  39. +-------------------------------------+
  40. 1 row in set (0.00 sec)
  41. mysql> DROP USER 'newuser';
  42. Query OK, 0 rows affected (0.14 sec)
  43. mysql> SHOW GRANTS FOR 'newuser';
  44. ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'
  45. ```
  46. ## MySQL compatibility
  47. * Dropping a user that does not exist with `IF EXISTS` will not create a warning in TiDB. [Issue #10196](https://github.com/pingcap/tidb/issues/10196).
  48. ## See also
  49. * [CREATE USER](/sql-statements/sql-statement-create-user.md)
  50. * [ALTER USER](/sql-statements/sql-statement-alter-user.md)
  51. * [SHOW CREATE USER](/sql-statements/sql-statement-show-create-user.md)
  52. * [Privilege Management](/privilege-management.md)