Cant login to Sql WorkBench as I forgot my root password

1.4k views Asked by At

I have forgotten my root@localhost password for MySQL and because of this, I am unable to connect to the database. How do I change it?. I tried the Alter method in which we have to set a new password in a txt file and then run. I tried that but it's still not changing.

I am using Windows 10.

1

There are 1 answers

0
AwatITWork On

if you have an Administrator user, then you can reset the MySQL root password using sysvar_init_file or init_file for short, here is how you can do it.

First, you have to Stop MySQL service, open Service and find MySQL Service and stop it.

Next, create an empty text file and put this, save it anywhere on your computer, let's say Desktop:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

Next, copy the file path you have created and navigate to your Bin folder where you have installed your MySQL on your computer.

"C:\Users\Awat\Desktop\MySQL Root Reset\rootReset.txt"

default similar to this one:

C:\Program Files\MySQL\MySQL Server Version\bin

After that, open CMD or Powershell as administrator and navigate to the installation folder and Bin

Type the following command, like me assuming you are in the Bin folder already

mysqld.exe --init-file="C:\Users\Awat\Desktop\MySQL Root Reset\rootReset.txt"

Please tell me if you have trouble implementing this.