Page 1 of 1

database users with host=% cannot connect from localhost

PostPosted: 20. January 2012 20:58
by matteosistisette
Hi,

When I create a new database user in phpMyAdmin, if I set the host to "%" (any host), the user won't be able to connect from localhost. For example, if some php script uses that username to connect to mysql, it will not be able to connect. I am forced to set the host to "localhost" when I create the user, and it works, but this is annoying because it will allow the user to connect only from localhost.

Note that this only happens with Xampp. With any other server I have ever tried, "any host" works just fine.

Is there a fix for this?

thanks
m.

Re: database users with host=% cannot connect from localhost

PostPosted: 20. January 2012 23:05
by Altrea
Hi,

MySQL does have predefined anonymous (means: not defined) usernames and hostnames and use them in a definite order.
The more precise a user is, the higher is his priority.

Means:
John@Doe (User John at Host Doe) = highest priority
%@Doe (Any User at Host Doe)
John@% (John at any Host)
%@% (any User at any Host) = lowest priority

Because there is already a rule for %@localhost it has a higher priority than your user@% rule.

The easiest way to get around that is to define the user for localhost too.

best wishes,
Altrea

Re: database users with host=% cannot connect from localhost

PostPosted: 20. January 2012 23:25
by matteosistisette
What is the rule that is defined for %@localhost (which is taking priority over givenuser@%)?

And why does this happen only with xampp? Is this a rule that is not present by default on common server configurations but it is in xampp? What's the rationale behind it?

thanks
m.

Re: database users with host=% cannot connect from localhost

PostPosted: 20. January 2012 23:34
by Altrea
matteosistisette wrote:why does this happen only with xampp? Is this a rule that is not present by default on common server configurations but it is in xampp? What's the rationale behind it?

The anonymous account is created by default in every mysql installation.
Most productive servers don't permit access by anonymous to mysql servers, so this users are deleted.

More to read here: http://dev.mysql.com/doc/refman/5.5/en/ ... users.html
(especially the part which starts with "The accounts created by these statements have the following properties:"

best wishes,
Altrea

Re: database users with host=% cannot connect from localhost

PostPosted: 21. January 2012 17:12
by JonB
Thanks for the informative answer, Altrea -- one I did not know! :shock:

Good Job
8)

Re: database users with host=% cannot connect from localhost

PostPosted: 21. January 2012 18:03
by matteosistisette
Thank you!

Re: database users with host=% cannot connect from localhost

PostPosted: 21. January 2012 20:03
by Altrea
You are both very welcome :)