连接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服务,即可。

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