Knowledgebase

Reset Mysql root password  Print this Article

Reset Your MySQL Root password on Windows

 

It is quite easy to reset your mysql root user password (if you know how!) In this howto I will try and explain how this is done.

1.

Prerequisites:

- You have to be logged on with administrator rights
- Open all command prompts as administrator:
o right-click: run as administrator
o or ctrl + shift + left click

 
2.

Lets Begin: Creating a txt file with the necessary sql commands

Start by making a txt file. I called it reset-mysql.txt.
In my case I saved it at “d:\reset-mysql.txt” In this file paste the following lines:

UPDATE mysql.user SET Password=PASSWORD('EnterPassword') WHERE User='root';
FLUSH PRIVILEGES;

Replace “EnterPassword” with your new password. Also make sure that the UPDATE and FLUSH commands are on separate lines!

 
3.

Stop the MySQL Server

If it is running as a service
- either go to the services snap-in and right-click on the service and select
- or open a command prompt and enter “net stop mysql”

If it is not running as a service use the windows taskmanager to stop the server

 
4.

Start the resetting of your root password

Open an administrator command prompt and navigate to your MySQL bin directory inside your MySQL install folder ("c:\Program Files\MySQL\MySQL Server 5.0\bin")

enter the following command

- mysqld-nt --init-file=D:\reset-mysql.txt --console

This will reset your root password to that which you have set in the text file.

Extra Info:
It seems that after executing this command the console hangs that is why I have added
the -- console command. This will send the messages to the console instead of to the log file.

 
5.

Restart the MySQL Service

self explanatory

 
6.

test to see if your password has been reset

- open a command prompt
- enter mysql –uroot –p
- when asked, enter your new password

 
7.

extra info:

When I do this it works great most of the times. But sometimes it seems that the mysql service hangs in between starting and stopping. Restarting the computer usually helps

Was this answer helpful?

Related Articles

Script a per database mysql backup in windows batch
 Create, schedule and change paths where applys for the batch script below :: If the time...