Centos下mysql5.7忘记登录密码

小插曲,部署项目前想把数据库导入进去。但是无奈忘记了密码了(密码策略自己没关,密码太长忘记了。。。。)

vim /etc/my.cnf

添加一行skip-grant-tables;保存退出即可
添加一行
再执行systemctl restart mysqld.service,重启数据库

后面直接mysql -u root,无密码登录进去,修改密码

顺序执行
use mysql;
update user set authentication_string = password("newPassword") where user="root" ;
flush privileges;//刷新
quit;

再重复上面vim /etc/my.cnf步骤,把刚刚的skip-grant-tables删掉并保存

再执行systemctl restart mysqld.service重启数据库
mysql -u root -p登录,输入你刚才的密码,发现可以登录了

如有错误,烦请提出~谢谢!

猜你喜欢

转载自blog.csdn.net/weixin_42553616/article/details/107608745