Reset root password for MySQL on windows

If you have problem accessing your MySQL database with this error
ERROR 1045: Access denied for user: ‘root@localhost’ (Using password: NO)

You can try reset your root password with the following steps:

1. Create a txt file with this content

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

2. Save the file as mysql-init.txt in c:\ (or any directory you want)

3. Stop MySQL service

4. Start MySQL service in command prompt with this command line

>c:\mysql\bin\mysqld --init-file=c:\\mysql-init.txt

5. Remove the txt file in created in step 2

Note: You can/need to specify correct path for the file and mysql directory for step 2 and 4.

Leave a Reply

Your email address will not be published. Required fields are marked *