1.以管理员打开cmd命令

 2.切换到你数据库所在的盆符的bin目录(如我的在E:\mysql-8.0.29-winx64\bin)

(cd  ../    返回上一级 )

3.输入mysqld --console --skip-grant-tables --shared-memory 指令(输入此指令前需要在任务管理器中关闭数据库运行)

 4.新打开一个cmd窗口,重复步骤1和步骤2,输入指令mysql -u root -p,此时直接回车进入数据库,不需要输入密码

 5.输入use mysql 启用数据库

6. 查询数据库select user,host,authentication_string from user;(数据库在8.0以上使用此命令)

select user,host,password from user;(数据库在8.0以下使用此命令)

7.更改密码update user set authentication_string='你的密码' where user='root';(8.0以上版本)

update user set password='你的密码' where user='root';(8.0以下版本)

 

推荐文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: