连接mysql报错:Access denied for user ‘root’@‘localhost’(using password: YES)的解决方法

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:ProgramDataMySQLMySQL 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服务,即可。

原文地址:https://www.cnblogs.com/luoa/p/10843980.html