1. 程式人生 > >MySQL登入 ERROR 1045 (28000) Access denied for user 'root'@'localhost' (using password NO)問題

MySQL登入 ERROR 1045 (28000) Access denied for user 'root'@'localhost' (using password NO)問題

一、問題

今天在CentOS安裝了mysql,由於mysql剛剛安裝完的時候,mysql的root使用者的密碼預設是空的,所以我使用命令mysql -uroot或mysql登入mysql,但是出現瞭如下錯誤:

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

二、解決方法

1.     停止mysql資料庫:systemctl stop mysqld

2.     用以下命令啟動MySQL,以不檢查許可權的方式啟動:

mysqld --skip-grant-tables &

此時可能會報另一個錯誤:2018-02-01T02:52:55.093724Z 0 [ERROR] Fatal error: Please read"Security" section of the manual to find out how to run mysqld asroot!

執行命令:mysqld--user=root --skip-grant-tables &

3.     登入mysql:mysql -uroot或mysql

4.     更新root密碼

mysql5.7以下版本:

UPDATE mysql.user SETPassword=PASSWORD('123456') where uSER='root';

mysql5.7版本:UPDATE mysql.userSET authentication_string=PASSWORD('123456') where USER='root'

5.     重新整理許可權:flush privileges;

6.     退出mysql

:exit或quit

7.     使用root使用者重新登入mysql

mysql-uroot –p

Enterpassword:<輸入新設的密碼123456>