在CentOS 中装了 MySQL,
自己在mysql.user 表中加了work用户,mysql> select Host, User, Password from user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *8894328AB2A0D2CD61F06 |
| 127.0.0.1 | root | *8894328AB2A0D2CD61F06|
| localhost | work | *897D277E60642557F7133 |
+-----------+------+-------------------------------------------+
我用 CentOS 的 work 账户登陆,并且以下面方式登陆就不能成功,并报ERROR 1045 (28000)
[work@Banana ~]$ mysql -u work -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'work'@'localhost' (using password: YES)
[work@Banana ~]$ mysql -h localhost -u work -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'work'@'localhost' (using password: YES)
[work@Banana ~]$ 
但是更改这个 localhost 为 127.0.0.1 后就可以登陆
[work@Banana ~]$ mysql -h 127.0.0.1 -u work -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trade of Oracle Corporation and/or its
affiliates. Other names may be trades of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 这其中是什么原因?

解决方案 »

  1.   

    本地host有没有解析?
      

  2.   

    有解析,root都可以正常登陆
    [work@Banana ~]$ ping localhost
    PING localhost (127.0.0.1) 56(84) bytes of data.
    64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.031 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.034 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.039 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.038 ms
    ^C
    --- localhost ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3244ms
    rtt min/avg/max/mdev = 0.031/0.035/0.039/0.006 ms
    [work@Banana ~]$