Modification Method of Forgetting MySQL Password under windows

Keywords: MySQL Windows Oracle mysqladmin

1. The Method of Modifying MySQL Password under windows
If you forget MySQL's password under Windows, you can do this:
1. Close the running mysql service: net stop mysql or terminate the mysqld.exe process in windows Task Manager or find the mysql service in the management tool and stop it;

The code is as follows:
C:\Users\Administrator>net stop mysql
MySQL Services are stopping.
MySQL Service has been successfully discontinued
2. Open the command line and go to the bin directory of mysql.
The code is as follows:
C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin
C:\Program Files\MySQL\MySQL Server 5.5\bin>
3. Input: mysqld-nt -- skip-grant-tables
Then return to the train, if there is no error message, it's OK.
Note: After skip-grant-tables parameter is used, login verification can be skipped.
The code is as follows:
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqld -nt --skip-grant-tables
140317 13:23:11 [Warning] option 'new': boolean value 't' wasn't recognized. Set
 to OFF.
4. Open another command line (because the DOS window just now can't move) and go to the bin directory of mysql.
5. Enter MySQL directly and return. If successful, there will be a MySQL prompt >
The code is as follows:
C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
6. Switch to mysql table
The code is as follows:
mysql>USE mysql;
7. The password can be changed:
The code is as follows:
UPDATE user SET password=PASSWORD("123456") WHERE user="root";
8. Refresh permissions, don't forget:
The code is as follows:
mysql>FLUSH PRIVILEGES;
9. Exit: (Qut, exit, ctrl+c, \ q, etc.) are many ways to exit;
10. Log off or restart the computer, then open the MySQL service, and log in using the username root and the new password set.

2. Three Common Ways to Change mysql Password
In most cases, ordinary users do not have permission to change the password, only those who apply for permission or root can change the password.
1. Method 1: Use mysqladmin

The code is as follows:
mysqladmin -u root password "123456"; 
If root has already set a password, use the following method
The code is as follows:
mysqladmin -u root password -p "123456";
2. Method 2: Use SET PASSWORD command without FLUSH PRIVILEGES;
The code is as follows:
mysql -u root -p
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456'); 
3. Method 3: Use UPDATE to edit user table directly
The code is as follows:
mysql> USE mysql;
mysql> UPDATE user SET Password = PASSWORD('123456') WHERE user='root'; 

Posted by segwaypirate on Wed, 17 Jul 2019 18:02:39 -0700