以管理员方式运行cmd窗口
执行net stop mysql关闭mysql服务
执行mysqld --console --skip-grant-tables --shared-memory进入无密码启动MySQL服务
这是这个cmd窗口不能动了
新开一个cmd窗口(以管理员身份运行)
输入命令mysql.exe -u root无密码登陆
将密码设置为空: UPDATE mysql.user SET authentication_string='' WHERE user='root' and host='localhost';
退出之后再重新登陆
mysql -u root -p 直接回车以空密码登陆
修改root用户密码:alter user user() identified by 'root';
C:\Windows\system32>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11Copyright (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;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user user() identified by 'root';
Query OK, 0 rows affected (0.07 sec)mysql> use mysql;
Database changed
mysql> quit
Bye