How to deal with forgotten database password

Windows version 5.6.51 and earlier
#当前账号设置密码
set password = password('123456');
#当前账号取消密码
set password = '';
(1) Open the console as an administrator and enter net stop m5 (My computer MySQL name is m5, according to my own changes)
(2) Enter the bin directory of m5 and enter mysqld --skip-grant-tables to start the server. This window does not close
(3) Open the second command console to log in to mysql , and you can log in directly without a password

Enter the following code, change the password to empty, and it will be OK

bin>mysql -uroot
mysql>select host,user,password from mysql.user;
mysql>update mysql.user set password = '';
mysql>exit

(4) Close all the windows, restart net start m5, then no password is needed.

 

 Windows 8.0.32 (all versions after 5.6.51)
#当前账号设置密码
set password = '123456';
#当前账号取消密码
set password = '';
(1) Open the console as an administrator and enter net stop m8 (My computer MySQL name is m8, according to my own changes)
(2)) Enter the bin directory of m8 and enter mysqld --console --skip-grant-tables --shared-memory to start the server. This window does not close
(3) Open the second command console and enter the bin of m8 to log in to mysql . You can log in directly without a password
Enter the following code, change the password to empty, and it will be OK
bin>mysql -uroot
mysql> select host,user,authentication_string from mysql.user;
mysql> update mysql.user set authentication_string='' where host='localhost'
and user='root';
mysql> select host,user,authentication_string from mysql.user;

(4) Close all windows, restart net start m8 , and the password is not needed at this time.

 

Guess you like

Origin blog.csdn.net/qq_57570052/article/details/132070794