不久前自學完完sql,下了mysql8.0.17,安裝配置好後探索著,想著用root賬戶登上去能不能刪除root賬戶呢,然後就想給自己一巴掌,,, 如何快速恢復root: 1.關閉mysql服務:win+R鍵鍵入services.msc,找到mysql服務,點擊stop; 2.刪除data文件夾及其 ...
不久前自學完完sql,下了mysql8.0.17,安裝配置好後探索著,想著用root賬戶登上去能不能刪除root賬戶呢,然後就想給自己一巴掌,,,
如何快速恢復root:
1.關閉mysql服務:win+R鍵鍵入services.msc,找到mysql服務,點擊stop;
2.刪除data文件夾及其文件:進入mysql文件夾,找到data文件夾並刪除;
3.初始化mysql:再次進入services.msc,運行mysql服務;cmd視窗進入mysql\bin文件路徑,運行mysqld --initialize --console 結果類似如下:
2019-08-07T02:08:11.300849Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2019-08-07T02:08:11.724874Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-07T02:08:12.024891Z 0 [Warning] InnoDB: Creating foreign key constraint
system tables.
2019-08-07T02:08:12.056893Z 0 [Warning] No existing UUID has been found, so we a
ssume that this is the first time that this server has been started. Generating
a new UUID: 35611a71-b8b8-11e9-8e24-28d24409926b.
2019-08-07T02:08:12.064893Z 0 [Warning] Gtid table is not ready to be used. Tabl
e 'mysql.gtid_executed' cannot be opened.
2019-08-07T02:08:12.076894Z 1 [Note] A temporary password is generated for root@
localhost: QTpg4Y!sh:dk
註意加粗語句中就有暫時生成的root賬戶密碼;
4.cmd運行mysql:鍵入mysql -u root -p+root密碼;註意:p是password的縮寫,按上面的例子就應鍵入:mysql -u root -pQTpg4Y!sh:dk -p和密碼一定要連在一起才有效,中間沒有空格;
5.修改臨時root密碼:運行sql語句:alter user root@localhost identified by ' root密碼 ’ ; 註意:密碼要包含在 英文單引號 ‘ ’ 中,不然無效報錯,末尾分號 ;也要寫。
6.查詢是否成功:運行sql語句: select user from mysql.user; 成功顯示root賬戶;
註意:本方法雖快捷有效,但會刪除所有資料庫文件,就是data文件夾里的資料庫。其他什麼添加skip-grant-tables來越過登錄認證的試過,對於8.0.17版的無效了。