Help Center/ Relational Database Service/ Troubleshooting/ RDS for MySQL/ SQL Issues/ Syntax Error Reported When GRANT Is Used to Grant All Privileges
Updated on 2023-11-03 GMT+08:00

Syntax Error Reported When GRANT Is Used to Grant All Privileges

Scenario

The grant statement can be used to grant all privileges on a database whose name is in letters. If this statement is used to grant all privileges on a database whose name is in digits, the following error is reported: You have an error in your SOL syntax.

Database name in letters:

grant all PRIVILEGES  on aaaaa.*  to  'TA01'@'%';

Database name in digits:

grant all PRIVILEGES  on 11111.*  to  'TA01'@'%';

Possible Causes

This problem is caused by a syntax error. In MySQL, backquotes (`) are introduced to distinguish MySQL keywords from common characters. You can enter a backquote (`) to ensure correct syntax.

Solution

If the database name is in digits, add a backquote (`) before and after the database name.

grant all PRIVILEGES  on `11111`.*  to  'TA01'@'%';