windows environment mysql forget root password solution

  • 2020-05-17 06:45:26
  • OfStack

1 friend is in a hurry: mysql forgot the password of root, let me help you to have a look at it. Because I haven't contacted mysql before, I found 1 piece of information from the Internet
Through my own practice has been successful! The mysql version is 5.1.
The following is the mysql password change information from the Internet:
Reference article:
Method to reset the Mysql Root password under windows
mysql changes passwords and forgets them
1. First, check whether mysql service is started or not. If it is started, stop the service first.
net stop mysql
Open the first cmd1 window, switch to mysql's bin directory, and run the command:
mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini" --console --skip-grant-tables
Note:
This command turns on the mysql service by skipping permission security checks so that you can connect to mysql without having to enter a user password. The mysql service is now on!
This window remains open.
2. Open the second cmd2 window and connect mysql:
Input command:
mysql -u root -p
A:
Enter password:
Enter here without entering a password.
And then you get a message that you've logged in successfully,
Command to use:
show databases;
Use the command to switch to mysql database:
use mysql;
Use the command to change the root password:
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
Refresh permissions:
FLUSH PRIVILEGES;
Then log out and log in again:
quit
Login again: you can close the previous cmd1 window. Then start the service with net start mysql
mysql -u root -p
The password input prompt appears, and you can log in after entering a new password:
Enter password: ***********
Display login information: successful on 1 cut ok

Related articles: