HiveBrain v1.2.0
Get Started
← Back to all entries
debugModerate

Error 1046 Mariadb: No database selected

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
error1046databaseselectedmariadb

Problem

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 different

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]>

Solution

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

Code Snippets

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

Context

StackExchange Database Administrators Q#27245, answer score: 10

Revisions (0)

No revisions yet.