windows forget MySQL password change method

  • 2020-06-12 10:48:20
  • OfStack

1. Method to modify MySQL password under windows
If you forget the MySQL password under Windows, you can do this:
1. Close the running MySQL service: net stop mysql or end the mysqld.exe process in windows task manager or find mysql service in the management tool and stop it;

C:\Users\Administrator>net stop mysql
MySQL  Service is being stopped .
MySQL  Service has been successfully stopped. 

2. Open the command line and go to mysql's bin directory;
C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin
C:\Program Files\MySQL\MySQL Server 5.5\bin>

3. Input: ES23en-ES24en -- ES25en-ES26en-ES27en
Enter, if there's no error message, that's it;
Note: After the parameter skip-ES31en-tables is used, login verification can be skipped;
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 one more command line (because the DOS window has been disabled), and go to the bin directory of mysql.
5. Enter mysql directly and press enter. If successful, the MySQL prompt will appear >
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
mysql>USE mysql;

7. You can change your password:
UPDATE user SET password=PASSWORD("123456") WHERE user="root";

8. Refresh permissions, don't forget:
mysql>FLUSH PRIVILEGES;

9. Exit (There are many ways to exit: quit, exit, ctrl+c, \q, etc.);
10. Log out or restart the computer, then open MySQL service and log in using the user name root and a new password.

2. Three ways to change your mysql password
In most cases, 1 general user does not have permission to change the password, only the permission or root user can change the password;
Method 1: Use mysqladmin

mysqladmin -u root password "123456"; 

If root has already set a password, do the following
mysqladmin -u root password -p "123456"; 

2. Method 2: SET PASSWORD command, no need to use FLUSH PRIVILEGES;
mysql -u root -p 
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456'); 

3. Method 3: Edit user table directly with UPDATE
C:\Users\Administrator>cd C:\Program Files\MySQL\MySQL Server 5.5\bin
C:\Program Files\MySQL\MySQL Server 5.5\bin>
0


Related articles: