0

I came across with an issue while I was trying to grant privileges to a database for a mysql user via t. I think it's because of the special chars in the database name.

This one is working:

/usr/bin/mysql -uroot -pXz5eaCqwvsT0pAr0gsf0tg1a -e "GRANT ALL PRIVILEGES ON dev_52000_nycny.* TO 'wp_j-5-1-5_nycny'@localhost"

That one is not working:

/usr/bin/mysql -uroot -pXz5eaCqwvsT0pAr0gsf0tg1a -e "GRANT ALL PRIVILEGES ON dev_j-5-1-5_nycny.* TO 'wp_j-5-1-5_nycny'@localhost"

I have tried few combinations but no luck:

/usr/bin/mysql -uroot -pXz5eaCqwvsT0pAr0gsf0tg1a -e "GRANT ALL PRIVILEGES ON 'dev_j-5-1-5_nycny'.* TO 'wp_j-5-1-5_nycny'@localhost"

/usr/bin/mysql -uroot -pXz5eaCqwvsT0pAr0gsf0tg1a -e "GRANT ALL PRIVILEGES ON dev_j\-5\-1\-5_nycny.* TO 'wp_j-5-1-5_nycny'@localhost"

/usr/bin/mysql -uroot -pXz5eaCqwvsT0pAr0gsf0tg1a -e "GRANT ALL PRIVILEGES ON 'dev_j\-5\-1\-5_nycny'.* TO 'wp_j-5-1-5_nycny'@localhost"

What should I do ?

mirza
  • 5,685
  • 10
  • 43
  • 73

1 Answers1

1

MySQL uses backticks to quote database, table, and column names that contain special characters. See When to use single quotes, double quotes, and backticks in MySQL

/usr/bin/mysql -uroot -pXz5eaCqwvsT0pAr0gsf0tg1a -e 'GRANT ALL PRIVILEGES ON `dev_j-5-1-5_nycny`.* TO "wp_j-5-1-5_nycny"@localhost`

Make sure you use single quotes around the -e argument, because backticks have special meaning to the shell when they're inside double quoted strings. I also changed the quotes around the username to double quotes to accomodate using single quotes around the whole query.

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612