If you have lost your mysql root password and you are unable to login to mysql, then as a last resort you can relogin by performing the following steps.
step1
——
You can stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the pathname of the .pid file in the following command:
Stop mysql service on the server. Do it in this way
shell> kill `cat /mysql-data-directory/host_name.pid` //note that ` is not single quotes it a back tab found in the top row of key
board (number row)
step2
——
Create a text file and place the following command within it on a single line:
SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(’123456′);
Save the file with any name. For this example the file will be mysql-init.
Step 3
——–
#
Restart the MySQL server with the special –init-file=~/mysql-init option:
shell> mysqld_safe –init-file=~/mysql-init &
The contents of the init-file are executed at server startup, changing the root password. After the server has started successfully you should delete ~/mysql-init.
Step 4
——–
You should be able to connect using the new password.
shell> mysql -u root -p
Then it will ask for password and give the password 123456
Login and reset the mysql password. Dont forget to delete the mysql-init file that we have created before restarting mysql.
Recent Comments