mysql密碼輸入正確但是登陸不進去

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password YES)  

  root賬戶缺失了訪問localhost主機的賬戶信息,導致無法本地登錄。

  [root@228827 ~]# mysql -uroot -p123456

  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  密碼正確的情況下,mysql數據庫已經禁止了root用戶在本地的登錄權限了。

  使用root用戶通過主機127.0.0.1登錄就可以正常進入mysql,127.0.0.1和localhost對mysql數據庫來講是不同的主機,

  [root@228827 ~]# mysql -uroot -p123456 -h 127.0.0.1

  這讓我想起了mysql下的user表。

  我們要進mysql看user表,一種方法可以通過上面的命令,如果不行,可以用下面的命令啓動數據庫,缺省密碼進入

代碼如下  

[root@228827 ~]# /etc/init.d/mysql stop

[root@228827 ~]# /usr/local/mysql/bin/mysqld_safe –skip-grant-tables &

[root@228827 ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 1

Server version: 5.1.57 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.


mysql> use mysql

Database changed

mysql> select user,host,password from user where user='root';

+——+——————-+——————————————-+

| user | host | password |

+——+——————-+——————————————-+

| root | % | *A50E066E106320CF4142 |

| root | centos | *A50E066E106320CF4142 |

| root | 127.0.0.1 | *A50E066E1063608320CF4142 |

+——+——————-+——————————————-+

3 rows in set (0.12 sec)


  發現user表host字段中沒有localhost,但是我的理解是%代表所有的主機都能登錄的,爲什麼localhost不能呢,同樣的情況我在5.0.45版的mysql上面做實驗就不會發生localhost無法登錄,我當前用的是5.1.57版的,難道是版本的問題?

  接下來的修改很明顯了:

代碼如下  

mysql> update user set host='localhost' where user='root' and host='%';

mysql> flush privileges;

  OK,退出mysql,重啓mysql就解決問題了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章