找回传说中mysql的root账户密码
重做系统 丢失了宝典 vps上的mysql root密码忘记了
一般会出现这样的错误
Access denied for user 'root'@'localhost'(using password: YES)
怎么办 怎么办
往下看
停掉server
systemctl stop mysqld.service
找到/etc/my.cnf文件
在[mysqld]后添加skip-grant-tables
记得保存啊
启动server
systemctl start mysqld.service
这时候神奇的事发生了
mysql -h localhost -uroot
不用密码 就可以进入了
这时候我们就可以通过语句来重新改一个密码
update mysql.user set authentication_string=PASSWORD("你的密码") where User = 'root';
commit;
flush privileges;
quit;
再次进入/etc/my.cnf文件
把skip-grant-tables前面加个# 让他闭嘴
重启服务
systemctl restart mysqld.service
最后
mysql -h localhost -uroot -p
输入新密码 就OK了
补充
如果只想让root 在本机上登录
update mysql.user set host='localhost' where user='root';
如果任何地方
update mysql.user set host='%' where user='root';
别忘了 flush privileges;
完
浙公网安备 33010602011771号