如何重设忘记的MySQL root密码? [英] How to reset the forgotten MySQL root password?

查看:74
本文介绍了如何重设忘记的MySQL root密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试重置MySQL的根密码.

I have been trying to reset the root password of MySQL.

我已经习惯了两种重置方法.但是我没明白.

I have used to two methods to reset. But I didnt get it.

已完成以下步骤,但对我而言不起作用:

Following steps are done, But it doesn't work for me:

METHOD-1:

1)停止运行MySQL服务,并创建了mysql-init.txt文件. mysql-init.txt包含:

1) Stopped running of MySQL services and created a mysql-init.txt file. mysql-init.txt contains:

USE mysql;

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

FLUSH PRIVILEGES;

2)我打开了命令提示符,并输入了以下内容:

2) I have opened the command prompt and i typed the following:

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld.exe --defaults-file="my.ini" --init-file="C:\\Users\\user-name\\Desktop\\mysql-init.txt" --console

我得到的错误如下:

无法打开所需的默认文件:C:\ Program Files \ MySQL \ MySQL Server 5.6 \ b 在\ my.ini中

Could not open required defaults file: C:\Program Files\MySQL\MySQL Server 5.6\b in\my.ini

默认处理中的致命错误.程序中止

Fatal error in defaults handling. Program aborted

METHOD-2:

I simply opened the command prompt and typed as follows:

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqladmin -uroot -psample password
vikash

I got the error as:

Warning: Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'

请帮助我重设密码...

Please help me to reset the password...

推荐答案

尝试停止mysql服务

Try stopping mysql service

/etc/init.d/mysqld stop

运行安全可执行文件跳过授权

Run the safe executable skipping grants

mysqld_safe --skip-grant-tables &

(后跟符号使您返回命令行)

(the trailing ampersand gets you back to the command line)

然后以root用户身份登录,无需密码

Then connect as root without password

mysql -uroot

您将进入mysql提示符,您可以在其中更新root的密码.

You'll be in the mysql prompt where you can update root's password.

编辑:我刚刚看到您正在使用Windows.好的,那么您的第一种方法应该几乎可以工作了.该文件应改为"UPDATE mysql.user",而不是

EDIT: I just saw you're using windows. Ok, then your first method should almost work. Instead of "UPDATE mysql.user" the file should read

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('vikash');

然后运行

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld.exe --init-file=C:\Users\user-name\Desktop\mysql-init.txt

我对可执行文件很好奇...所有这些空格可能会使Windows感到困惑.也许在与可执行文件相同的文件夹中创建init文件会更容易,所以您只需要运行

I'm curious about the executable though... all those blank spaces can probably get windows confused. Perhaps it would be easier to create your init file in the same folder as the executable so you just have to run

mysqld.exe --init-file=mysql-init.txt

其中可能还有其他可执行文件. mysqld-nt,mysqld-safe等.如果mysqld无法正常工作,也可以尝试其他方法.

There might be other executables in there. mysqld-nt, mysqld-safe, etc. If mysqld doesn't work, try the others too.

这篇关于如何重设忘记的MySQL root密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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