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.
Reset password on windows
- Login to system with administrator rights
MySqlfrom service control(run services.msc). Find
MySqlservice and stop it if not running as services or do not want to stop gracefully then kill
mysqld.exefrom 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
FLUSHstatements each on a single line. The
UPDATEstatement resets the password for all
rootaccounts, and the
FLUSHstatement 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.exein your MySql installation location
- Now run following command from command window
C:>C:Program Filesmysqlbinmysqld --init-file=C:\\init.txt
- This will start
MySqland reset all root user password which you have given init.txt file
- Now kill
mysqld.exefrom task manager and start mysql service normally.
Generic method for all systems
- Stop mysql services or kill mysqld
- start it with the
--skip-grant-tablesoption. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use
--skip-grant-tablesin conjunction with
--skip-networkingto prevent remote clients from connecting.
- Connect to the mysqld server with command
- 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.