Access denied for user 'root'@'localhost' (using password:YES) Mysql5.7

时间:2021-08-08 20:56:24

解决方案:

(1) 打开MySQL目录下的my.ini文件,在文件的最后添加一行“skip-grant-tables”,保存并关闭文件。(my.ini在C:\ProgramData\MySQL\MySQL Server 5.7\my.ini)

Access denied for user 'root'@'localhost' (using password:YES) Mysql5.7

(2)重启MySQL服务。

(3)通过命令行进入MySQL的BIN目录,输入“mysql -u root -p”(不输入密码),回车即可进入数据库。

C:\Program Files\MySQL\MySQL Server 5.7\bin>

(4)执行“use mysql;”,使用mysql数据库。

Access denied for user 'root'@'localhost' (using password:YES) Mysql5.7

(5)执行“update user set authentication_string=password('xxxx') where User='root'; (修改root的密码)

Access denied for user 'root'@'localhost' (using password:YES) Mysql5.7

(6)分配权限

 grant all privileges on *.* to root@localhost identified by "xxxx" ;

(7)打开MySQL目录下的my.ini文件,删除最后一行的“skip-grant-tables”,保存并关闭文件。

(8)重启MySQL服务。

(9)在命令行中输入“mysql -u root -p xxxx”,即可成功连接数据库。