之前mysql(8.0.16)忘记密码了,但是在网上找的方法依然无法解决,后来才发现是因为找到的方法是解决mysql 5 的问题的,有些命令并不适用于mysql 8 。
现在写一下mysql 8 忘记密码的解决方法吧
- 先停掉mysql的服务 命令: net stop mysql
- 进入mysql的bin目录,使用命令
mysqld --console --skip-grant-tables --shared-memory
可以在没有密码的情况下进入mysql,注意命令末尾没有分号
- 使用管理员身份另打开一个窗口,进入到mysql的bin目录下,输入mysql -uroot可以无密码登录mysql
- 然后use mysql;里面有user表,输入
update user set authentication_string=’’ where user=‘root’ and host=‘localhost’;
清空root用户的密码,authentication_string的值是空
- 再重新打开窗口,启动服务 net start mysql
- 进入到bin目录,无密码登录mysql
- 重新设置root用户的密码
alter user root@localhost identified by ‘新密码’;
- 下次登录的时候,就可以使用这个密码登录了