1、打开mysql的安装路径
2、搜索.err文件
3、用记事本打开这个文件
Ctrl+F搜索password,将A temporary password is generated for root@localhost后的密码记录下来。
4、使用临时密码登录mysql进行密码修改
必须手动输入密码,不允许复制!
我的MySQL版本是8.0,所以使用的语句为:
mysql> flush privileges;mysql> alter user 'root'@'localhost'IDENTIFIED BY 'NewPassword';
使用新的密码进行登录,就可以成功登录mysql啦。