mysql忘记root用户密码找回步骤

修改或找回root密码步骤
1.修改MySQL的登录设置: # vi /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 保存并且退出vi。 2.重新启动mysqld # /etc/init.d/mysqld restart ( service mysqld restart )
3 mysql -uroot -p 回车
mysql> USE mysql ; 
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; 

运行报错

改为 update mysql.user set authentication_string=password('123456a') where user='root';

4.刷新权限 

mysql> flush privileges ; 
mysql> quit;
5.将MySQL的登录设置修改回来 
# vi /etc/my.cnf 
将刚才在[mysqld]的段中加上的skip-grant-tables删除 
保存并且退出vi。
6.重新启动mysqld 
# /etc/init.d/mysqld restart   ( service mysqld restart )
重新登录成功 ,root用户设置ok。

 

MySQL密码的恢复方法二
有可能你的系统没有 safe_mysqld 程序(比如我现在用的 ubuntu操作系统, apt-get安装的mysql) , 下面方法可以恢复
1. 停止mysqld; 
/etc/init.d/mysql stop
(您可能有其它的方法,总之停止mysqld的运行就可以了)
2. 用以下命令启动MySQL,以不检查权限的方式启动; 
mysqld --skip-grant-tables &
3. 然后用空密码方式使用root用户登录 MySQL; 
mysql -u root
4. 修改root用户的密码; 
mysql> update mysql.user set password=PASSWORD('newpassword') where User='root'; 
mysql> flush privileges; 
mysql> quit 
重新启动MySQL
/etc/init.d/mysql restart
就可以使用新密码 newpassword 登录了。




posted on 2018-11-07 16:13  kevin_yang123  阅读(37156)  评论(3编辑  收藏  举报