1、停止数据库

  net stop mysql

2、打开cmd窗口,运行如下命令:

  mysqld  --skip-grant-tables


3、打开第二个cmd,连接mysql,运行如下命令:
  mysql -uroot -p

  遇到需要输入密码时,直接回车,就可以进去

 

4、连接好mysql之后,运行命令

  show databases;

 

5、继续使用如下命令

use mysql;

6、使用命令修改root密码(两种情况)

  • 版本为5.7以前的mysql,运行这条语句(此处的新密码为你要设置的新密码)

  UPDATE user SET Password=PASSWORD('新密码') where USER='root';

  

  • 版本为5.7及其之后的运行这条语句

  UPDATE user SET authentication_string=PASSWORD('新密码') where USER='root';

  

原因是:mysql中密码的字段名由password变为了authentication_string

For Mysql before 5.7 it is "password"

Since MySQL 5.7 it is "authentication_string"

 

7、刷新权限

FLUSH PRIVILEGES;

8、退出数据库

quit

9、重新登录数据库,并输入密码就可以了

mysql -uroot -p


 

相关文章:

  • 2021-07-29
  • 2021-11-22
  • 2021-08-05
猜你喜欢
  • 2021-09-27
  • 2021-07-10
  • 2021-09-09
  • 2021-10-24
  • 2018-11-07
  • 2022-02-07
  • 2021-09-18
相关资源
相似解决方案