Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

mysql password modification method mysql forgot the password how to do


May 16, 2021 MySQL



In windows systems, mysql still has more ways to change passwords. This article introduces four ways mySQL can modify root passwords.


Method 1: Modify it with the SET PASSWORD command

First log in to mysql, the general command format is: mysql sgt; set password for username@localhost password ('new password');

Example:

mysql> set password for root@localhost = password('123'); 


Method 2: Modify with mysqladmin

Format: mysqladmin -u username -p old password password new password

Example:

mysqladmin -uroot -p123456 password 123 

This command changes the password of the user from 123456 to 123


Method 3: Edit the user table directly with UPDATE

First log in to mysql

mysql> use mysql; 
mysql> update user set password=password('123') where user='root' and host='localhost'; 
mysql> flush privileges; 

The above code is to change root's password to 123


All three methods are in the case of remembering the old password, if the user forgot the password, then what to do?


Method 4: Forget the old password modification method

1. Turn off the running MySQL service.

2. Open the DOS window and go to the mysql-bin directory.

3. Enter mysqld-skip-grant-tables to enter. - -skip-grant-tables This instruction allows users to skip permission table authentication directly when they start the MySQL service again.

4. Open another DOS window (because the DOS window just now can't move) and go to the mysql\bin directory.

5. Enter mysql to enter, and if successful, the MySQL prompt will appear.

6. Connection permission database: use mysql;

6. Change the password: update user set password ("123") where user=root"; ( Don't forget to add a final sign).

7. Refresh permissions (must step): flush privileges;

8. Exit quit.

9. Sign out of the system, re-enter, log in with the username root and the new password 123 just set.


The above is the w3cschool for everyone to bring mysql database password modification method, I hope to help you.