1. 程式人生 > >進入MySQL時報ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

進入MySQL時報ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using
password: YES)
在這裡插入圖片描述

解決:

1、關閉mysql service mysql stop
2、依次執行以下命令,如果/etc目錄下有my.cnf檔案直接修改,如果沒有就拷一份,如下
cp /usr/share/mysql/my-default.cnf /etc/my.cnf

3、修改/etc/my.cnf檔案
在mysqld後新增 skip-grant-tables,儲存關閉後後,重啟mysql服務
在這裡插入圖片描述
4、重啟mysql服務,service mysql restart
進入mysql中 mysql -uroot
在裡面執行
可以進行修改,把root改為自己的使用者名稱,localhost改為自己的主機名
set password for ‘root’@‘localhost’ = password(‘root’);

如果在執行是報如下錯誤,就重新整理許可權在執行 flush privileges;

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