This is a read-only copy of the MariaDB Knowledgebase generated on 2024-12-03. For the latest, interactive version please visit https://mariadb.com/kb/.

DROP USER

语法

DROP USER [IF EXISTS] user_name [, user_name] ...

描述

DROP USER 语句删除一个或多个 MariaDB 帐户。它从所有授权表中删除帐户的权限行。要使用此语句,您必须具有全局 CREATE USER 权限或 mysql 数据库的 DELETE 权限。每个帐户的命名格式与 CREATE USER 语句相同;例如,'jeffrey'@'localhost'。如果您仅指定帐户名称部分,则使用主机名部分为 '%'。有关指定帐户名称的其他信息,请参见 CREATE USER

请注意,如果您指定的帐户当前已连接,则在关闭连接之前不会删除它。连接不会自动关闭。

如果指定的任何用户帐户不存在,则会出现 ERROR 1396 (HY000)。如果发生错误,则 DROP USER 仍将删除未导致错误的帐户。对于所有未被删除的用户仅生成一个错误:

ERROR 1396 (HY000): Operation DROP USER failed for 'u1'@'%','u2'@'%'

CREATEDROP 操作失败,对于用户和角色而言,会产生相同的错误代码。

IF EXISTS

如果使用了 IF EXISTS 子句,如果用户不存在,MariaDB 将返回一个提示而不是错误。

示例

DROP USER bob;

DROP USER foo2@localhost,foo2@'127.%';

IF EXISTS:

DROP USER bob;
ERROR 1396 (HY000): Operation DROP USER failed for 'bob'@'%'

DROP USER IF EXISTS bob;
Query OK, 0 rows affected, 1 warning (0.00 sec)

SHOW WARNINGS;
+-------+------+---------------------------------------------+
| Level | Code | Message                                     |
+-------+------+---------------------------------------------+
| Note  | 1974 | Can't drop user 'bob'@'%'; it doesn't exist |
+-------+------+---------------------------------------------+

参见

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.