1.查看正在运行的mysql服务进程,执行命令: tasklist | findstr mysql
C:\Users\Administrator>tasklist | findstr mysql
映像名称 PID 会话名 会话 内存使用
mysqld.exe 6740 Services 0 189,936 K
2.结束正在运行的mysql服务进程
C:\Users\Administrator>taskkill /F /PID 6740
成功: 已终止 PID 为 6740 的进程。
3.打开一个cmd窗口输入mysqld --skip-grant-tables,注意这个cmd命令窗口不要关闭
C:\Users\Administrator>mysqld --skip-grant-tables
执行这个命令后,会夯在这里...
如果没有,可能是因为没有关闭mysql服务导致!
4.重新打开一个cmd窗口,运行下面命令
C:\Users\Administrator> mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql Database changed
# 设置新的密码为123456 mysql> update user set authentication_string=password('123456') where user='root'; Query OK, 0 rows affected, 1 warning (0.06 sec) Rows matched: 1 Changed: 0 Warnings: 1
mysql> flush privileges; Query OK, 0 rows affected (0.06 sec)
mysql> exit; Bye
5.继续以管理员身份运行cmd,输入net start mysql启动MySQL服务
先查看是否在运行,因为有的时候window上这时mysqld已经在服务就不用启动了!
C:\Users\Administrator>tasklist | findstr mysql 映像名称 PID 会话名 会话 内存使用 mysqld.exe 8068 Console 1 178,944 K
如果没有启动,通过下方这样启动即可!
C:\Users\Administrator>net start mysql MySQL 服务正在启动 . MySQL 服务已经启动成功。
6.以重置后的root密码登录测试,如下mysql -uroot -proot
C:\Users\Administrator>mysql -uroot -proot mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.