Access denied for user 'root'@'localhost' (using password:YES) Mysql5.7

解決方案:
mysql

(1) 打開MySQL目錄下的my.ini文件,在文件的最後添加一行「skip-grant-tables」,保存並關閉文件。(my.ini在C:\ProgramData\MySQL\MySQL Server 5.7\my.ini)sql

(2)重啓MySQL服務。數據庫

(3)經過命令行進入MySQL的BIN目錄,輸入「mysql -u root -p」(不輸入密碼),回車便可進入數據庫。ide

C:\Program Files\MySQL\MySQL Server 5.7\bin>spa

(4)執行「use mysql;」,使用mysql數據庫。命令行

(5)執行「update user set authentication_string=password('xxxx') where User='root'; (修改root的密碼)3d

(6)分配權限blog

 grant all privileges on *.* to root@localhost identified by "xxxx" ;ip

(7)打開MySQL目錄下的my.ini文件,刪除最後一行的「skip-grant-tables」,保存並關閉文件。
string

(8)重啓MySQL服務。

(9)在命令行中輸入「mysql -u root -p xxxx」,便可成功鏈接數據庫。

相關文章
相關標籤/搜索