Home  >  Article  >  Database  >  Solving the problem of forgetting the password of MySQL 5.7 under Windows 8.1 (picture and text)

Solving the problem of forgetting the password of MySQL 5.7 under Windows 8.1 (picture and text)

黄舟
黄舟Original
2017-07-20 15:12:361520browse

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.

【 Background】

I encountered a very embarrassing thing while studying recently. 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 MySQL permission review and enter MySQL

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

                                                                                                    ​ ​ ​ ​ Then, open the file, and under mysqld, add the code skip-grant-tables to skip permissions Review.                                                     The first step: enter services.msc with win+R, 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: When I first queried password, I found that this field did not exist. Later, I checked online and found out that MySQL5.7 had replaced the password field with authentication_string7c97327a16a651b778ccaaffac1dcac2.)
==================================                                                             Learn about it.

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';


3. Refresh permissions , 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 does not include the skip- Comment out grant-tables? 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 successfully enter!

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


【Summary】

I originally wanted to start over I have the heart to install MySQL, but I still persist until the problem is successfully solved. The process is a bit painful, but the ending is happy.

The above is the detailed content of Solving the problem of forgetting the password of MySQL 5.7 under Windows 8.1 (picture and text). 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