How to recover/Change MySQL Password

心已入冬 提交于 2019-12-02 17:03:59

问题


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. Stop Mysql Service
  2. Write this in cmd:

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.

Thanks


回答1:


Stop the mysql service

Edit the my.ini file or my.cnf file

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

skip-grant-tables

Restart the mysql service.

Open the MySQL console

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

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.

Pre MYSQL version 5.7

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

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;

Note that the update may report that it has updated more than one row, that because there are actually 3 user accounts with the userid of 'root' each with a different domain i.e. 127.0.0.1, localhost and ::1

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

Stop the mysql service

Edit the my.ini file or my.cnf file

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

DO NOT Leave this parameter in the ini file its a HUGH security hole.

Restart the mysql service.

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

|improve this answer

来源:https://stackoverflow.com/questions/37028695/how-to-recover-change-mysql-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!