Home > Database > Mysql Tutorial > How to solve the problem of forgetting the root password of MySQL5.7 under Windows 8.1

How to solve the problem of forgetting the root password of MySQL5.7 under Windows 8.1

小云云
Release: 2018-01-06 14:42:54
Original
1197 people have browsed it

I encountered an embarrassing thing while studying recently. I forgot my MySQL password, so I couldn’t log in to MySQL. The solutions found on the Internet are not reliable. The editor below will share with you the solution to the problem of forgetting the root password of MySQL5.7 under Windows 8.1. Friends who need it can take a look. I hope it can help everyone.

[Background]

I encountered an embarrassing thing recently while studying. I forgot my MySQL password, so I couldn’t log in to MySQL.

There are many solutions on the Internet, and I have tried many, but I am still tortured by various error reports from the window. Thanks to the help of experts, the solution to MySQL forgotten password has become clear. I hope the solution process in this blog can help readers.

[Problem Solving Process]

1. Skip the permission review of MySQL and enter MySQL

First, find the my.ini configuration file of MySQL.        

                                                            ​

​ Then, open the file, and under mysqld, add a code skip-grant-tables to skip permission review.                                                                           Enter services.msc, find the mysql service, and restart the service.

I suspect that this step was not performed correctly when I did it before. (Also, I also have some questions here. Why do I have two MySQL services, one MySQL and one MySQL57. There is no configuration file in the MySQL properties, but MySQL57 does.) ​

                                 

2. Reset the password in the mysql.user table

First, enter the DOS window with cmd, enter MySQL, and press Enter. You can successfully enter MySQL without a password. (I couldn't even achieve this step before, so when I successfully entered MySQL, don't mention how happy I was~~)
Then, let's take a look at what's in the mysql.user table. SELECT User, Host, Authentication_String from mysql.user

## (TIPS: In the beginning, check the password and find that this field does not exist. Later, I checked mesql5. I learned that mysql5. 7 The password field was replaced with authentication_string)

=======================. ==========                                                                                                                                                                                   ​


The Host column specifies the IP range that users are allowed to log in to.

For example, user=root Host=192.168.21.1. What this means here is that the root user can only access through the client of 192.168.21.1. And % is a wildcard character. If Host=192.168.1.%, it means that any client with an IP address prefix of "192.168.21." can connect. If Host=%, it means that all IPs have connection permission. Therefore, when opening a remote connection, most people directly change the Host to %, because it is super convenient.



=================================

Very important The first step: we set the host and password.

Update mysql.user set host="%",authentication_string=password('root') where user='root';
Copy after login

3. Refresh permissions to update the data that has been changed and is in the buffer. flush privileges

There is also a little question: after refreshing, if you enter mysql directly, there is no way to skip the password review and enter MySQL, but the configuration file clearly has not commented out the skip-grant-tables sentence. ? Will refreshing ignore the configuration file just modified?

Anyway, I later commented out the skip-grant-tables sentence in my.ini. .             

#4. Log in with your password!

First, enter mysql -u root -p, then enter the password you just set, and you can enter successfully!

Finally, please develop a good habit and remember your baby password. :)         

【Summary】

I originally wanted to reinstall MySQL, but I still persisted until the problem was successfully solved. The process is It's a bit painful, but the ending is happy.

Related recommendations:

How to install MySQL5.7 on Windows 10 and modify the forgotten root password

Mysql forgets the root password under Window Detailed graphic and text introduction on how to reset

MySQL - How to operate if you forget your Root password

The above is the detailed content of How to solve the problem of forgetting the root password of MySQL5.7 under Windows 8.1. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template