Home > Database > Mysql Tutorial > body text

How to solve the problem of forgetting mysql password

藏色散人
Release: 2023-01-05 16:14:09
Original
18428 people have browsed it

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.

How to solve the problem of forgetting mysql password

#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
Copy after login

How to solve the problem of forgetting mysql password

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
Copy after login

How to solve the problem of forgetting mysql password

After restarting, log in with mysql -uroot -p
and you will find that we can log in without a password

    mysql -uroot -p
Copy after login

How to solve the problem of forgetting mysql password

  • Reset password

First select the mysql database

   use mysql
Copy after login

Then update the password

   update user set authentication_string = password ( 'new-password' ) where user = 'root' ;
Copy after login

How to solve the problem of forgetting mysql password
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'
Copy after login

, an error will be reported: ERROR 1054 (42S22): Unknown column 'password' in 'field list';
How to solve the problem of forgetting mysql password

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

How to solve the problem of forgetting mysql 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!

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