How to reset MYSQL root password in Windows if root password is forgotten?
Somehow I have forgotten my MYSQL root password. I tried all possible combination, but everything went in vain, so what the options I have? Either uninstall MYSQL and reinstall it again, since it is just my local development instance or need to figure out a solution to find out the password or change it.
Uninstalling and reinstalling it, is not a wise solution. So other only option is change it. Below are the steps to change the root password for MYSQL in Windows.
1) Log on to your system as Administrator or make sure that you have the administrator privileges.
2) Stop the MYSQL server. To do that, open the Start Menu and type services. It will open the Services window, if not got to the Control Panel > System and Security > Administrative Tools and click Services there. Find the MYSQL services and stop it.
3) Create a text file containing Sql statement to update the root password, save the file in a specific location. Let assume the file is stored in the C drive, and file name is mysql-init.txt
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
4) Now open the command prompt as Administrator, and go the bin directory of the MYSQL. For me the directory path is "C:\Program Files\MySQL\MySQL Server 8.0\bin"
5) Execute the below command
mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini"
--init-file="C:\\mysql-init.txt" --console
--console is used to output server logs to the console, that way we know what is happening to the command we have executed.
--defaults-file To figure out the path, go to the services windows, which you performed in Step 2, right click the MYSQL, and click the properties in the popup window, get the data from the path to executable settings
6) Once you executed the command, Start the MYSQL services again.
7) Now login to the MYSQL as root user with the new password.
That's all, you get into the MYSQL.
Happy Programming...!!!
Comments
Post a Comment