The solution for mysql forgotten password: first find the "my.ini" file; then add "skip-grant-tables" under "mysqld"; then restart the mysql service; finally reset the password through update. Can.
#The operating environment of this article: Windows 7 system, Dell G3 computer, MySQL Server 5.7.
What should I do if I forget mysql password?
When we install and use MySQl, sometimes we may inevitably forget the password. If you forget the password, you can follow the following plan:
Find my. ini file
The my.ini file is the MySQl setting file. If you are at the default installation address, the file is under
C:\ProgramData\MySQL\MySQL Server 5.7
But ProgramData is hidden in normal state
Set permission authentication skip
That is, add skip-grant-tables under [mysqld]
skip-grant-tables
Restart the mysql service
Here you can directly enter continuously in the command line or find the mysql service in the service to restart
net stop mysql net start mysql
After restarting, log in with mysql -uroot -p
and you will find that we can log in without a password
mysql -uroot -p
Reset password
First select the mysql database
use mysql
Then update the password
update user set authentication_string = password ( 'new-password' ) where user = 'root' ;
Note: What needs to be changed here is the authentication_string. Instead of password field
, if you enter
update user set Password=password('new-password') where user='root'
, an error will be reported: ERROR 1054 (42S22): Unknown column 'password' in 'field list';
The reason is mysql There is no password field in the database anymore. The password field has been changed to authentication_string
Remove the added skip- in the my.ini file grant-tables
Restart mysql service
Log in with new password
Recommended study: "mysql video tutorial"
The above is the detailed content of How to solve the problem of forgetting mysql password. For more information, please follow other related articles on the PHP Chinese website!