解決mysql"Access denied for user'root'@'IP地址'"問題


在按照前面文章中方法搭建Mysql數據庫之后,發現其他機器還是不能訪問,

參考以下文章對權限進行修改之后,發現本地機器中root不能訪問了。

http://www.cnblogs.com/ycsfwhh/archive/2012/08/07/2626597.html

后來使用 select host, user, grant_priv from user;

發現grant_priv一列有問題,只有有grant_priv的用戶才能對其他用戶賦予權限。

修改成以下這樣,就好了。

+-------------------------------------------------+------+------------+
| host                                            | user | grant_priv |
+-------------------------------------------------+------+------------+
| %                                               | root | Y          |
| gzns-ecom-baiduhui-201605-m42n02.gzns.baidu.com | root | Y          |
| 127.0.0.1                                       | root | Y          |
| ::1                                             | root | Y          |
| localhost                                       |      | N          |
| gzns-ecom-baiduhui-201605-m42n02.gzns.baidu.com |      | N          |
| localhost                                       | root | N          |
+-------------------------------------------------+------+------------+

 

結果發現本機還是連不上:

$ mysql -P8306 -uroot -p123456
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

再查表看到password這一欄:

mysql> select host, user, Password, grant_priv from user;
+-------------------------------------------------+------+-------------------------------------------+------------+
| host                                            | user | Password                                  | grant_priv |
+-------------------------------------------------+------+-------------------------------------------+------------+
| %                                               | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y          |
| localhost                                       | root |                                           | Y          |
| 127.0.0.1                                       | root |                                           | Y          |
| ::1                                             | root |                                           | Y          |
| localhost                                       |      |                                           | N          |
| gzns-ecom-baiduhui-201605-m42n02.gzns.baidu.com |      |                                           | N          |
| 127.0.0.1                                       |      | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | N          |
+-------------------------------------------------+------+-------------------------------------------+------------+
7 rows in set (0.00 sec)

發現localhost和root這一欄,沒有密碼,所以不用密碼才能登錄:

$ mysql -P8306 -uroot         
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 294
Server version: 5.5.30-log Source distribution

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM