windows under mysql forget root password solution

  • 2020-05-09 19:25:18
  • OfStack

Method 1:

1. Enter under the DOS window net stop mysql5 or net stop mysql

2. Open an DOS window, which requires you to switch to the bin directory of mysql.
1 create a batch in bin directory 1.bat, cmd.exe run 1 to switch to the current directory, and then enter
mysqld-nt --skip-grant-tables;

or

mysqld --skip-grant-tables;

Don't close the window

3. Open another DOS window, mysql -u root

4. Input:


use mysql
update user set password=password("new_pass") where user="root";
flush privileges;
exit

5. Using the task manager, find the mysqld-nt process and terminate the process

Or the following steps
1, stop MYSQL service, CMD open DOS window, enter net stop mysql
2. In the CMD command line window, go to the MYSQL installation directory such as E:\Program Files\MySQL\MySQL Server 5.0\bin
Model command:
Enter e: enter,
Type cd "E:\Program Files\MySQL\MySQL Server 5.0\ Server"
Note that you need to enter the double quotation marks as well, so you can go to the Mysql installation directory.
3. Enter mysql security mode, that is, when mysql gets up, it can enter the database without entering the password.
The command is: mysqld-nt -- skip-grant-tables
4. Re-open an CMD command line window, enter mysql-uroot-p, and log in MySQL with an empty password (no password required, just press enter).
5. Enter the following command to change the password of the root user (note: there is a "dot" in the middle of mysql.user)
mysql > update mysql. user set password=PASSWORD(' new password ') where User='root';
6. Refresh the permission table
mysql > flush privileges;
7, exit
mysql > quit
So the MYSQL super administrator account ROOT has been reset. Next, finish the mysql-nt. exe process in the task manager and restart MYSQL. (you can also restart the server directly)
After rebooting MYSQL, you can log in MYSQL with the new ROOT password!
Method 2:

First, create a new pwdhf.txt in the installation directory of MySQL. Enter SET PASSWORD FOR '@'localhost' = PASSWORD('***** *');

The red part is the new password that needs to be set
Stop the MySQL service with the windows service management tool or task manager (task manager K drops the mysqld-nt process)
The Dos command prompt goes to the bin directory under the MySQL installation directory as mine is D:\Program Files\MySQL\MySQL Server 5.1\bin
Then run: mysqld-nt -- init-file =.. / pwdhf txt
Stop the MySQL database service after execution (task manager K dropped the mysqld-nt process) and restart MYSQL in normal mode


Related articles: