連接mysql報錯:Access denied for user ‘root’@‘localhost’(using password: YES/NO)的解決方法

linux系統

1,在Linux,先進入/etc,修改my.cnf,任意一行加上"skip-grant-tables"。

2,重啓MySQL:service mysqld restart

3,use mysql;

update mysql.user set authentication_string=password(‘your new password’) where user=‘root’;

4,flush privileges;
exit;
5,重啓MySQL:service mysqld restart (這步可以省略)

windows系統

版本是5.7

1、默認安裝地址:C:\ProgramData\MySQL\MySQL Server 5.7

在這裏插入圖片描述

2、打開my.ini,在mysqld下面加上 skip-grant-tables

表示不用密碼就可以登錄。

3、打開電腦的服務,重啓MySQL服務。

4、進入MySQL命令行

不用輸入密碼,直接進入

5、use mysql;

update mysql.user set authentication_string=password(‘your new password’) where user=‘root’;

flush privileges;

6、再回到my.ini,給skip-grant-tables加上“#”,表示註釋掉。

7、重啓MySQL服務,即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章