不久前自學完完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版的無效了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/80288.html
標籤:MySQL
下一篇:Mysql資料庫操作(命令列)
