在不知道当前密码的情况下重置MySQL根密码 [英] Resetting MySQL root password when current password is not known

查看:145
本文介绍了在不知道当前密码的情况下重置MySQL根密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了安装了mysql的服务器.我没有任何用户的mysql密码,甚至没有root用户(尽管我有linux root密码).另外,我只知道另一个用户帐户besbes是root,并且该用户帐户没有执行任何操作的权限,甚至没有SELECT权限.

I have inherited a server that has mysql installed on it. I don't have the mysql password for any user, not even root (although I have the linux root password). Plus, I am only aware of one other user account besdies root, and that one does not have privileges to perform any action, not even SELECT.

我尝试停止mysql servicw,使用跳过授予表"选项重新启动,并且仅在没有密码的情况下登录:

I tried stopping the mysql servicw, restarting with the skip grant tables option, and just logging in without password:

service mysqld stop
service mysqld start --skip-grant-tables &
mysql -u root

但是出现以下错误:

Access denied for user 'root'@'localhost' (using password: NO)

然后我尝试重置密码:

mysqladmin -u root password 'newpw'

但这还会导致访问被拒绝错误.

But that also gives an access denied error.

我还尝试了以其他用户身份登录(没有pw)并执行以下命令:

I also tried logging in as the other user (without pw) and executing the following command:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';

并收到此错误:

ERROR 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user'

我也尝试过删除mysql并重新安装,但出现相同的错误.

I have also tried removing mysql and reinstalling, but I get the same errors.

有什么建议吗?

推荐答案

两个选项:

如果要使用--skip-grant-tables,则可能不需要直接通过init脚本传递选项,则可能需要直接启动mysqld.

If you want to use --skip-grant-tables you may need to start mysqld directly as the options aren't necessarily passed along through the init script.

否则,请尝试这些说明手册.

这篇关于在不知道当前密码的情况下重置MySQL根密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆