Window下如何恢复被删除的Mysql8.0.17 Root账户及密码
不久前自学完完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=457902019-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 identified by ' root密码 '
; 注意:密码要包含在 英文单引号 ‘ ' 中,不然无效报错,末尾分号 ;也要写。
6.查询是否成功:运行sql语句: select user from mysql.user; 成功显示root账户;
注意:本方法虽快捷有效,但会删除所有数据库文件,就是data文件夹里的数据库。其他什么添加skip-grant-tables来越过登录认证的试过,对于8.0.17版的无效了。
总结
以上所述是小编给大家介绍的window下如何恢复被删除的mysql8.0.17 root账户及密码,希望对大家有所帮助!