Bug #66071 MySQL's treatment of hostnames is retarded
Submitted: 28 Jul 2012 21:23 Modified: 29 Aug 2012 16:10
Reporter: Josh Endries Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Security: Privileges Severity:S3 (Non-critical)
Version:All OS:Any
Assigned to: CPU Architecture:Any
Tags: authentication, MySQL, mysql-server, premissions, privileges

[28 Jul 2012 21:23] Josh Endries
Description:
For some ridiculous reason, MySQL treats 127.0.0.1, localhost, and "%" (and probably ::1) differently. They should be the same. It's always been this way, AFAICT. Get with it, people. If you have a user@'%', or one of the others, you should be able to log in via -h localhost. It's sad that this has remained a bug for so many years.

How to repeat:
create db, grant for user@'%', try to log in.

Suggested fix:
Make it work correctly.
[29 Jul 2012 16:10] Valeriy Kravchuk
I think this case is clearly explained in the manual, http://dev.mysql.com/doc/refman/5.1/en/access-denied.html:

"If you cannot figure out why you get Access denied, remove from the user table all entries that have Host values containing wildcards (entries that contain '%' or '_' characters). A very common error is to insert a new entry with Host='%' and User='some_user', thinking that this enables you to specify localhost to connect from the same machine. The reason that this does not work is that the default privileges include an entry with Host='localhost' and User=''. Because that entry has a Host value 'localhost' that is more specific than '%', it is used in preference to the new entry when connecting from localhost! The correct procedure is to insert a second entry with Host='localhost' and User='some_user', or to delete the entry with Host='localhost' and User=''."

Read http://dev.mysql.com/doc/refman/5.1/en/account-names.html and http://dev.mysql.com/doc/refman/5.1/en/connection-access.html.

Everything works exactly as documented. If you want to change documented behavior, that would be a feature request.
[30 Aug 2012 1: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".