忘记mysql的root密码

如果忘记root密码或其他用户密码,不要急,按下面操作即可。
1. 编辑mysql主配置文件 my.cnf
vim /etc/my.cnf   在[mysqld]字段下添加参数  skip-grant  
2. 重启数据库服务
service mysqld restart
3. 这样就可以进入数据库不用授权了
mysql -uroot
4. 修改相应用户密码
use mysql;
update user set password=password('your password') where user='root';
                                                            密码                                      用户
其他为格式。
 flush privileges;
5.  修改/etc/my.cnf 去掉 skip-grant , 重启mysql服务

来自http://www.aminglinux.com/bbs/thread-252-1-1.html

原文地址:https://www.cnblogs.com/cuizhipeng/p/4224956.html