linux上的mysql忘记密码

1、查看mysql服务是否起来

2、通过修改mysql的配置文件/etc/my.conf,跳过验证,:wq保存退出

skip-grant-tables

3.重启数据库

运行命令:systemctl restart mysqld

 4.进入到mysql数据库

运行命令:mysql -u root 

5、修改密码

运行语句:use mysql;
继续运行语句:update mysql.user set authentication_string=password('root_password') where user='root';    
root_password替换成你想要的密码,符合密码复杂程度
最后运行语句:flush privileges;

7、将刚才添加的语句从/etc/my.cnf删除

重启mysql服务,即可

参考:https://www.cnblogs.com/black-fact/p/11613361.html

原文地址:https://www.cnblogs.com/peng9527/p/14154030.html