修改或找回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' ;
1.jpg
运行报错

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

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。
3.jpg

MySQL密码的恢复方法二

有可能你的系统没有 safe_mysqld 程序(比如我现在用的 ubuntu操作系统, apt-get安装的mysql) , 下面方法可以恢复

  1. 停止mysqld;
    /etc/init.d/mysql stop

(您可能有其它的方法,总之停止mysqld的运行就可以了)

  1. 用以下命令启动MySQL,以不检查权限的方式启动;
  2. --skip-grant-tables &
  3. 然后用空密码方式使用root用户登录 MySQL;
  4. -u root
  5. 修改root用户的密码;
    mysql> update mysql.user set password=PASSWORD('newpassword') where User='root';

mysql> flush privileges;
mysql> quit

重新启动MySQL
/etc/init.d/mysql restart

就可以使用新密码 newpassword 登录了。


本文来源第三方文章:

https://www.cnblogs.com/kevin-yang123/p/9923203.html

感谢!Thanks!

本文来源第三方文章:

https://www.cnblogs.com/kevin-yang123/p/9923203.html

感谢!Thanks!

本文来源第三方文章:

https://www.cnblogs.com/kevin-yang123/p/9923203.html

感谢!Thanks!

标签: none

添加新评论

选择表情