mysql error 1130 hy000:Host 'localhost' is not allowed to connect to this mysql server 解決方案


ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server

D:\Wamp\mysql-5.6.21\bin>mysql.exe -uroot -p
Enter password:
ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server

此處是root賬戶沒有本地數據庫的訪問權限,所以無法連接數據庫,需要使用grant給root賬戶授權。

授權之前需要登錄到數據庫,使用skip-grant-tables參數

skip-grant-tables  顧名思義,數據庫啟動的時候 跳躍權限表的限制,不用驗證密碼,直接登錄。

 

編輯 my.ini,在[mysqld]的段中加上一句:skip-grant-tables 

[mysqld] 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
skip-name-resolve 
skip-grant-tables 

臨時解決方案,亦可以用於忘記mysql root用戶密碼時使用,安全性也比較難以保證。

 

然后登陸到root賬戶,此時不需要輸入密碼就可以進入,然后grant授權

 

mysql> grant all privileges on *.* to root@'localhost' identified by "123456";

  

如果此處報錯  ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

只需要刷新權限就行,flush privileges;

然后再執行授權命令就行了。

 

最后記得在配置文件中刪除 skip-grant-tables  參數,然后重啟MySQL服務。


免責聲明!

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



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