如何恢复/更改MySQL密码 [英] How to recover/Change MySQL Password

查看:131
本文介绍了如何恢复/更改MySQL密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,一切正常.今天,当我启动mysql时,它开始给我以下错误消息

Yesterday Everything was working fine. Today when i start mysql its start giving me following error message

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

我不知道它何时以及如何设置密码.

I don't know when and how it sets password.

现在我正在尝试设置密码,但是它没有更新它.

Now i am trying to set password, but its not updating it.

我正在按照以下步骤恢复密码.

I am using following steps to recover password.

  1. 停止Mysql服务
  2. 在cmd中写入:

C:\ Program Files \ MySQL \ MySQL Server 5.5> mysqld.exe --defaults-file ="my.ini" --init-file ="d:\ mysql-init.txt"-控制台

C:\Program Files\MySQL\MySQL Server 5.5>mysqld.exe --defaults-file="my.ini" --init-file="d:\mysql-init.txt" --console

它开始向我显示进度,但在此消息后停止响应

It start showing me progress but stop responding after this message

160504 18:01:54 [Note] Server socket created on IP: '0.0.0.0'.
160504 18:01:54 [Note] Event Scheduler: Loaded 0 events
160504 18:01:54 [Note] mysqld.exe: ready for connections.
Version: '5.5.38'  socket: ''  port: 3306  MySQL Community Server (GPL)

我等待了十多分钟,但此后未显示任何进展.

I waited for more than 10 minutes but its not showing any progress after this..

请指导我如何解决此问题.

Kindly guide me how to resolve this problem.

谢谢

推荐答案

停止mysql服务

编辑my.ini文件或my.cnf文件

在ini文件中找到[mysqld]部分,并将该行直接添加到[mysqld]

Find the [mysqld] section in the ini file and add this line directly after the section [mysqld]

skip-grant-tables

重新启动mysql服务.

Restart the mysql service.

打开MySQL控制台

现在,我们将为root用户重置密码,当然,这可以用于重置任何用户的密码.

Now we are going to reset the password for the root user, of course this could be used to reset any users password.

在mysql>命令提示符下输入以下2条命令,每条命令在行尾加一个半冒号,并在每行后按ENTER,以将命令发布给mysql.

Enter the following 2 commands at the mysql> command prompt, each with a semi colon at the end of a line, and press ENTER after each line to issue the command to mysql.

MYSQL 5.7之前版本

Pre MYSQL version 5.7

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

在MYSQL 5.7版之后,列名已更改

Post MYSQL version 5.7 the column name changed

UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;

请注意,该更新可能会报告它已更新了多行,因为实际上有3个用户帐户的用户名均为"root",每个用户帐户都具有不同的域,即127.0.0.1,localhost和:: 1

现在在mysql命令提示符下输入quit退出mysql.

Now enter quit at the mysql command prompt to exit mysql.

停止mysql服务

编辑my.ini文件或my.cnf文件

Edit the my.ini file or my.cnf file

在ini文件中找到{mysqld]部分,然后删除我们之前添加的skip-grant-tables参数.

Find the {mysqld] section in the ini file and Remove the skip-grant-tables parameter we added earlier.

请勿将此参数留在ini文件中,这是一个巨大的安全漏洞.

重新启动mysql服务.

Restart the mysql service.

您现在应该可以使用用户名'root'和您刚刚为该用户设置的新密码,使用phpmyadmin登录.

You should now be able to login with phpmyadmin using the userid 'root' and the new password you have just set for that user.

这篇关于如何恢复/更改MySQL密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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