Home  >  Article  >  Database  >  How to reset mysql password

How to reset mysql password

一个新手
一个新手Original
2017-09-07 16:12:482408browse


Preface

As the title says, I believe there are many solutions provided by Brother Lei Feng on the Internet. When I tried those methods, I encountered a problem and did not solve it successfully. , as for what the problem is, let me sort it out again.

Step one: Stop the running MySQL process

You can execute the net stop mysql command on the command line or close it directly in the process manager.
You can also click Stop directly (if you are using wamp), as shown below:
stop mysql

Step 2: Start MySQL in safe mode

First enter mysql The installation directory, such as D:\mysql\bin
Execution
D:\mysql\bin>mysqld.exe –skip-grant-tables
If nothing unexpected happens, the current window will enter hang at this time status, Do not close the window, reopen another command line windowExecute the following command
D:\mysql\bin>mysql -uroot -p
You will be prompted to enter the password at this time, ignore the password , press Enter directly to enter mysql.

Step 3: Change the password

mysql>use mysql;
mysql>update user set password=password(“new_password”) where user=”root”;
Then Here comes the problem. When you reach this step, you may report this error:
How to reset mysql password
The modification failed. The reason is very simple. There is no password field in the table. So what exactly should be changed? It's very simple. You can know it by directly entering the user table and executing the following command:
mysql>How to reset mysql password * from user where user="root";
You can see the following output:
How to reset mysql password
Obviously, there is no password field in the table, but there is a field authentication_string (authentication string) corresponding to a 64-bit encrypted string. Just replace password with authentication_string.
mysql>update user set authentication_string=password(“new_password”) where user="root”;
Then execute
mysql>flush privileges;
mysql>exit;
The password was modified successfully.

Step 4: Turn off the safe mode of MySQL

Just restart. If it cannot be restarted, you can restart the computer and then restart.

The above is the detailed content of How to reset mysql password. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn