Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.
GRANT ALL ON my-database.* TO my-user@10.0.0.1 IDENTIFIED BY 'password';
ERROR 1046 (3D000): No database selected

Ok I have created a database with a "-" on the name (did the same thing on the user)... then when I try to set the grants on it the database wont work.

If I use the base the error is diferent

MariaDB [(none)]> use my-base
Database changed
MariaDB [my-base]> GRANT ALL ON 'my-base'.* TO 'my-user'@'10.0.0.1' IDENTIFIED BY 'password';
ERROR 1064 (42000): 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 ''my-base'.* TO 'my-user'@'10.0.0.1' IDENTIFIED BY 'password'' at line 1
MariaDB [my-base]> 
share|improve this question
1  
In regards to the second error if you set your database, if you're not running in ANSI-quote sql_mode, ' doesn't escape a database object. Use the back tick ` –  Derek Downey Oct 19 '12 at 15:03
1  
Slight correction to myself...ANSI_QUOTES affects the double-quotes for escaping...single-quotation never does :) –  Derek Downey Oct 19 '12 at 15:14
add comment

1 Answer 1

up vote 6 down vote accepted

Try escaping it with backticks?

GRANT ALL ON `my-database`.* TO `my-user`@`10.0.0.1` IDENTIFIED BY 'password';

Also, if you already have a user my-user@10.0.0.1, you don't need to provide the IDENTIFIED BY... portion of your grant statement

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.