In Windows, how does one forget the password of mysql? _ MySQL

Source: Internet
Author: User
Tags mysql update
How to solve the problem of forgetting the password of mysql in Windows bitsCN. comWindows

Mysql5.0

Http://www.bitsCN.com/article/21984.htm
Method 1:

1. input in DOS window

net stop mysql5 

Or

net stop mysql 

2. open a DOS window and switch to the bin directory of mysql.
Generally, a batch of 1.bats is created in the binlog. the content is "cmd.exe", and you can switch to the current directory, and enter

mysqld-nt --skip-grant-tables; 

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. use the Task Manager to locate the mysqld-nt process and end the process.
Or the following steps
1. stop MYSQL. open the DOS window in CMD and enter net stop mysql.
2. in the CMD command line window, enter the MYSQL installation directory, such as E:/Program Files/MySQL Server 5.0/bin.
Demo command:
Enter e: enter,
Enter cd "E:/Program Files/MySQL Server 5.0/bin"
Note that double quotation marks must also be entered to enter the Mysql installation directory.
3. enter the mysql security mode, that is, when mysql is up, it can enter the database without entering the password.
Command:

mysqld-nt --skip-grant-tables 

4. open a new CMD command line window and enter

Mysql-uroot-p: use a blank password to log on to MySQL (press enter without a password)

5. enter the following command to modify the password of the root user (note: There is a "point" in the middle of mysql. user ")

Mysql. user: database name. table name
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 MYSQL Super Administrator account ROOT has been reset, then in the task manager to end the mysql-nt.exe this process, restart MYSQL!

(You can also restart the server)
After MYSQL is restarted, you can log on to MYSQL with the newly set ROOT password!

Method 2:

First, create a new pwdhf.txt under the MySQL installation directory, and enter the text:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('*****'); 

The red part shows the new password to be set.
Use windows service management tools or task manager to stop the MySQL service (Task Manager K drops the mysqld-nt process)
Doscommand prompt to the bin directory under the MySQL installation directory.

D:/Program Files/MySQL Server 5.1/bin
Then run:

mysqld-nt --init-file=../pwdhf.txt 

After the execution is complete, stop the MySQL database service (Job Manager K drops the mysqld-nt process), and then start MYSQL again in normal mode.

Mysql5.1 or later

1. First, check whether the mysql service is started. if it has been started, stop the service. run the following command in the Start menu:

net stop mysql 

2. open the first cmd window, switch to the mysql bin directory, and run the following command:

mysqld --defaults-file="C:/Program Files/MySQL/MySQL Server 5.1/my.ini" --console --skip-grant-tables

Note:

This command skips the permission security check and enables the mysql service. when you connect to mysql, you do not need to enter the user password.

3. open the second cmd window and connect to mysql:

Enter the following command:

mysql -uroot -p

Appears:

Enter password:

Press enter here without entering the password.

Then there will be information about successful logon,

4. run the following command:

show databases;

5. run the following command to switch to the mysql database:

use mysql;

6. use the command to change the root password to 123456:

UPDATE user SET Password=PASSWORD('123456') where USER='root';

7. refresh permission:

FLUSH PRIVILEGES;

8. exit and log on again:

Quit

Log on again:

mysql -uroot -p

9. enter a new password to log on:

Enter password :***********

Show logon information: everything will be OK if the logon is successful

10. restart the mysql service.

net start mysql

If anything is wrong, you are welcome to make a brick o

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.