windows下mysql5.7忘记密码情况下重置密码问题暨Access denied for user 'root'@'localhost'问题解决方案

1、停止mysql服务,修改my.ini,设置无密码登录

(注:mysql5.7的data目录及my.ini默认在此目录:C:\ProgramData\MySQL\MySQL Server 5.7。)

修改内容:在[mysqld]下增加skip-grant-tables,增加后重新mysql服务。

2、打开cmd,运行mysql -u root,进入mysql命令行

3、运行以下命令,重置密码:

 1)、update user set authentication_string=password("newpassword") where user="root"

 2)、flush privileges

(注,5.7之前版本,user表中authentication_string字段为password,5.7版本改为了authentication_string。)

4、停止mysql服务,为安全起见,将my.ini中skip-grant-tables项去掉

5、启动mysql服务,用mysql -u root -p以及新密码登录

6、若登录依然提示Access denied for user 'root'@'localhost',重复步骤1~5。



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