由於mysql版本的更新,當遇到這個問題時在網上搜索的很多方法並不完全使用,因此記錄當前解決mysql-8.0.18 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的方法。
解決方案:
1. 快捷鍵 windows + R ;輸入 services.msc ; 找到MySQL 停止其服務
2. 在命令行程序中;注意需要以管理員權限運行cmd程序,不然無法關閉mysqld進程
>>tasklist |findstr mysqld 這行命令可以用來查看mysqld是否在運行,在運行中則可以查到它的PID
>>taskkill /F /PID xxxx xxxx是從前面一條命令得到的PID值
3.跳過權限登錄MySQL 服務器端
在cmd中執行 mysqld --console --skip-grant-tables --shared-memory
此時cmd程序會阻塞,關閉cmd程序 然后重新以管理員權限運行cmd
然后在cmd命令行中輸入 mysql 就能連接上MySQL 服務器端了
4.無密碼登錄
mysql -u root -p
按 enter鍵 進入
5.修改密碼為空
use mysql;
select user,host,authentication_string from user;
### 密碼設置為空
update user set authentication_string='' where user='root';
flush privileges;
quit;
6.修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';