Fix MySQL Error 1064 When Granting Privileges

MySQLpermissions

I'm trying to add privileges for a newly created user in my database (CLI). But i am getting an error, probably because i have a dash in my db name but how do you work around it?

Error:

    You have an error in your SQL syntax; check the manual that corresponds to
    your MySQL server version for the right syntax to use 
    near '-acc.* TO 'bivv-acc'@'localhost'' at line 1

The actual command:

GRANT ALL PRIVILEGES ON bivv-acc.* TO 'bivv-acc'@'localhost';

Note: I am in my database, not in the overview of all the databases. Any clues?

Cheers,

Best Answer

Try to escape dash using the backticks like

GRANT ALL PRIVILEGES ON `bivv-acc`.* TO 'bivv-acc'@'localhost';

Check the manual which says:

If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.

...

The identifier quote character is the backtick ("`")