Bug #6985 Can't connect to mysql server on localhost
Submitted: 3 Dec 2004 12:01 Modified: 3 Dec 2004 13:07
Reporter: Sebastian Nohn Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S1 (Critical)
Version:4.1.7 OS:Linux (SuSE Linux 9.1, Kernel 2.6.4)
Assigned to: CPU Architecture:Any

[3 Dec 2004 12:01] Sebastian Nohn
Description:
After creating a database with

    mysqladmin -uroot create monitorsr

And creating a user with

    GRANT ALL PRIVILEGES
           ON monitorsr.*
           TO monitor@'%'
           IDENTIFIED BY 'monitor';

When trying to connect to the local database server from the shell I get an error:

looser@duron$ mysql -umonitor -pmonitor monitorsr
ERROR 1045 (28000): Access denied for user 'monitor'@'localhost' (using password: YES)

The same happens when not saying which database I want to use:

looser@duron$ mysql -umonitor -pmonitor          
ERROR 1045 (28000): Access denied for user 'monitor'@'localhost' (using password: YES)

The corresponding database tables don't contain any special things, so i doubt this is either a documentation bug or a bug in mysql itself.

mysql> select * from db where db = 'monitorsr';
+------+-----------+---------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+
| Host | Db        | User    | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv |
+------+-----------+---------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+
| %    | monitorsr | monitor | Y           | Y           | Y           | Y           | Y           | Y         | N          | Y               | Y          | Y          | Y                     | Y                |
+------+-----------+---------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+
1 row in set (0.00 sec)

mysql> select * from user where user = 'monitor';
+------+---------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+
| Host | User    | Password                                  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections |
+------+---------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+
| %    | monitor | *1975D095AC033CAF4E1BF94F7202A9BBFEEB66F1 | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                |          |            |             |              |             0 |           0 |               0 |
+------+---------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+
1 row in set (0.00 sec)

Of course I checked for any typos.

How to repeat:
Do the same like described above
[3 Dec 2004 12:04] Sebastian Nohn
This may help you:

looser@duron$ mysql -V
mysql  Ver 14.7 Distrib 4.1.7, for pc-linux (i686)

looser@duron$ /usr/sbin/mysqld --version
/usr/sbin/mysqld  Ver 4.1.7-standard for pc-linux on i686 (Official MySQL RPM)
[3 Dec 2004 12:18] MySQL Verification Team
Hi,

Thank you for the report, but this is not a bug. Please, read carefully MySQL documentation at:
http://dev.mysql.com/doc/mysql/en/Connection_access.html
[3 Dec 2004 12:43] Sebastian Nohn
Did you even read my report?

Adding a user with password like described on 

http://dev.mysql.com/doc/mysql/de/Adding_users.html

Does'nt work. Maybe it's not clear enough or anything, but from your documentation I expect

GRANT ALL PRIVILEGES
           ON monitorsr.*
           TO monitor@'%'
           IDENTIFIED BY 'monitor';

to create a user "monitor" with password "monitor" that is allowed to connect to database "monitorsr" from any host.

That does'nt work like expected. You documentation examples are nice, but most users search for an simple solution.
[3 Dec 2004 13:07] MySQL Verification Team
Sebastian, please read carefully link that I gave you.
If you have record for ''@localhost user MySQL uses this entry. That is why you get "Access denied" error.
[3 Dec 2004 14:21] Sebastian Nohn
I see no use in having this non-user by default so I suggest to remove this on default installations.