參考博客:https://blog.csdn.net/kerecs/article/details/51498754
https://blog.csdn.net/zwj1030711290/article/details/80039780
1.在mysql安裝目錄下刪除data目錄
2.my.ini目錄下的路徑由\改為\\
basedir = D:\\studySoft\\mysql-8.0.11
datadir = D:\\studySoft\\mysql-8.0.11\\data
3.管理員身份模式進入mysql下的bin目錄
4.移除已注冊服務:
mysqld remove
5.初始化:mysqld --initialize --console
2018-04-20T02:35:01.507037Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2018-04-20T02:35:01.507640Z 0 [System] [MY-013169] [Server] D:\Program\MySQL8\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 11064 2018-04-20T02:35:01.508173Z 0 [ERROR] [MY-010340] [Server] Error message file 'D:\Program\MySQL\share\english\errmsg.sys' had only 1090 error messages, but it should contain at least 4512 error messages. Check that the above file is the right version for this program! 2018-04-20T02:35:05.464644Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ 2018-04-20T02:35:07.017280Z 0 [System] [MY-013170] [Server] D:\Program\MySQL8\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed
標紅為生成的root密碼,記錄下來。
6.注冊服務:
mysqld -install
7.更改密碼:
輸入 mysql -uroot -p命令后,輸入之前記錄的root密碼
8.更改密碼命令
MySQL8.0.4以前,執行
SET PASSWORD=PASSWORD('[修改的密碼]');
mysql8.0.4以后
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '修改的密碼';
9.啟動服務:net start mysql