Bug #9272 Cannot connect to a newly created database
Submitted: 18 Mar 2005 11:19 Modified: 26 Apr 2005 13:30
Reporter: Alessandro Forghieri Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.2 OS:Linux (RedHat ES 3.0)
Assigned to: CPU Architecture:Any

[18 Mar 2005 11:19] Alessandro Forghieri
Description:
On 5.0.2, RH Linux I have gone crazy trying to solve the following:

After
CREATE DATABASE foo;

a) root can connect to database;
b) anybody else cannot;
c) whereas anybody can connect to test;

A summary of my grant tables:
mysql> select user,host from user;

+--------+-------------------+
| user   | host              |
+--------+-------------------+
| dbatmm | %                 |
| root   | %                 |
| scott  | %                 |
|        | bo7pw5.my.dom |
| root   | bo7pw5.my.dom |
|        | localhost         |
| root   | localhost         |
| scott  | localhost         |
+--------+-------------------+

8 rows in set (0.00 sec)

mysql> select user,host,db from db;

+--------+------+-----------+
| user   | host | db        |
+--------+------+-----------+
| root   | %    | db        |
|        | %    | test      |
+--------+------+-----------+

No combination of grant statements has been able to solve this. 

Final solution:

insert into db values ('%','foo','someuser','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

How to repeat:
CREATE DATABASE foo;

try to connect from anywhere as non root user (fails) - then issue all the grants you want and see if you can connect.

Suggested fix:

the entire GRANT system should be replaced with something more sensible, not to mention understandable and easy to diagnose (--log, for instance helps zilch on this).
[20 Mar 2005 11:43] MySQL Verification Team
Hello,

Thank you for the report, but I don't understand what exactly problem is.
If user doesn't have privileges on the database (or global level privileges) he can't connect to this database.
Please, explain your problem more detailed.
[20 Mar 2005 11:57] Alessandro Forghieri
To clarify further:

The problem with this is that I have been unable to find the GRANT statement that gives a user access to the DB, either by copying the examples supplied in the documentation OR guessing at what the right statement may be.

To accomplish my goal (which, as stated is creating a database and a user that can access it from any host) I had to inspect the db grant table and maually insert the required values.

So either the documentation is blasted, or the GRANT command does not work as advertised or...
[25 Mar 2005 14:03] MySQL Verification Team
Which grant statement have you tried to grant user access to db ??
[25 Apr 2005 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[26 Apr 2005 13:30] Alessandro Forghieri
Look, I really do not remeber what exact GRANT combination I tried so I can only answer that I tried all the GRANT variations that appeared to be able to solve the requisite at hand i.e.:

1) allow a given user/password combination access to a database from any host.

None worked - however, the straight insert did.

I'll bounce your question back: what is the GRANT statement that solves (1)?
The obvious answer would be:

GRANT ALL PRIVILEGES ON db.dbatmm  TO dbatmm@'%';

But I am pretty sure that that did not work, and the small obvious variariations on that tune didn't work, either.