向名为 "Grant" 的用户授予权限?

Granting privileges to a user named "Grant"?

CREATE USER 'Grant'@'localhost' IDENTIFIED BY 'bestpasswordever';

如何向名为 "Grant" 的用户授予权限?它会引发错误。

GRANT INSERT, DELETE
ON table
TO Grant@localhost;

错误:'Grant' 在此位置无效。需要标识符。

在使用保留关键字或标识符时必须使用反引号,否则将非法字符用作标识符

GRANT INSERT, DELETE
ON table
TO `Grant`@localhost;

根据 the documentation:

也可以使用撇号或双引号

Quote user names and host names as identifiers or as strings, using either backticks (`), single quotation marks ('), or double quotation marks ("). For string-quoting and identifier-quoting guidelines, see Section 9.1.1, “String Literals”, and Section 9.2, “Schema Object Names”.

...但我是纯粹主义者,在 MySQL 中始终使用反引号作为标识符。

GRANT INSERT,DELETE
ON table
TO 'Grant'@'localhost';

请参阅文档中的 Section 6.2.4 (Specifying Account Names)

Account name syntax is 'user_name'@'host_name'.