Sometime specially on developer machine we forget MySql
root password in that case it is not possible to reset root password normally. In that case you have to create new password as given below. There are two methods to do this.
Table of content
Reset password on windows
- Login to system with administrator rights
- Stop
MySql
from service control(run services.msc). FindMySql
service and stop it if not running as services or do not want to stop gracefully then killmysqld.exe
from Task manager. - Create one text file with following SQL queries at any location like (C:init.txt)
UPDATE mysql.user SET Password=PASSWORD(\'MyNewPass\') WHERE User=\'root\'; FLUSH PRIVILEGES;
- Write the
UPDATE
andFLUSH
statements each on a single line. TheUPDATE
statement resets the password for allroot
accounts, and theFLUSH
statement tells the server to reload the grant tables into memory so that it notices the password change. - Open command prompt(RUN –>cmd)
- Now locate
mysqlbinmysqld.exe
in your MySql installation location - Now run following command from command window
C:>C:Program Filesmysqlbinmysqld --init-file=C:\\init.txt
- This will start
MySql
and reset all root user password which you have given init.txt file - Now kill
mysqld.exe
from task manager and start mysql service normally.
Generic method for all systems
- Stop mysql services or kill mysqld
- start it with the
--skip-grant-tables
option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use--skip-grant-tables
in conjunction with--skip-networking
to prevent remote clients from connecting. - Connect to the mysqld server with command
shell> mysql
- Run following sql with new password
mysql> UPDATE mysql.user SET Password=PASSWORD(\'MyNewPass\') -> WHERE User=\'root\'; mysql> FLUSH PRIVILEGES;
- Stop server and re-start normally.