一、背景
两台电脑同时装数据库,导致忘记之前电脑的数据库密码,百度了各种找回密码的方式,最终发现5.0版本的MySQL与8.0以后的找回方式不同!!!
二、解决方案
1.先打开第一个cmd命令窗口
step1.停用mysql服务
net stop mysql
step2.跳过输入密码的验证
mysqld --console --skip-grant-tables --shared-memory
2.打开第2个cmd命令窗口(第一个不要关闭)
step1.启动mysql服务
net start mysql
step2.输入用户名、密码(密码不用输直接回车即可)
mysql -u root -p
step3.将密码置空
use mysql
alter user set authentication_string='' where user='user';
exit
3.关掉两个cmd窗口,打开新的窗口,无密码登录(还是直接回车)
step1.登录后,修改密码
alter user 'root'@'localhost' identified with mysql_native_password by '111111';
#with mysql_native_password 是为了连接Navicat不报错
step2.一定要记得刷新权限!!!
flush privileges