Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Granting privileges to a user named "Grant"?

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

How do I grant permissions to a user who is named "Grant"? It throws an error.

GRANT INSERT, DELETE
ON table
TO Grant@localhost;

Error: 'Grant' is not valid at this position. Expecting an identifier.

like image 622
MontyLemons Avatar asked Apr 24 '20 18:04

MontyLemons


People also ask

How do I grant privileges to user?

Database-Specific Privileges To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name.

How do I grant privileges to a user in SQL?

You can use the SQL GRANT statement to grant SQL SELECT, UPDATE, INSERT, DELETE, and other privileges on tables or views. The WITH GRANT OPTION clause indicates that JONES can grant to other users any of the SQL privileges you granted for the ORDER_BACKLOG table.


2 Answers

You have to use backticks when using reserved keywords or identifiers with otherwise illegal characters as identifiers

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

Apostrophes or double quotes are fine, too as per 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”.

...but I'm a purist and will always use backticks in MySQL, for identifiers.

like image 76
Lukas Eder Avatar answered Oct 15 '22 13:10

Lukas Eder


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

See Section 6.2.4 (Specifying Account Names) in the documentation.

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

like image 22
Steve Brandli Avatar answered Oct 15 '22 15:10

Steve Brandli