以管理員方式運行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