Recover mySQL root password

#########———————————————————-#############
———————+++++++++++++++++++++++++————————-
=================================================

[1] A times we may not be having the MySQL default root password especialy when
we are running a live system(Linux live CD ) and in some “other” situations.
This should not stop us on our tracks.
So get around this I came up with small tut on how reset the root user password
in under well few steps.
NB:tested on MySQL ver.5.0.67
[2] To start with check wether the Mysql service is running.

code:

#service mysql status <ENTER>

if mysql is running then do this to stop it

code:

#service mysql stop <ENTER>

you should get a message that the mysql service has been stopped

[3] Now that we have stoped the service will start it once more but this time in safe
mode and skip the grant tables which are used by mysql to the passwords(google this).

code:

 # mysqld_safe --skip-grant-tables <ENTER>


NB: This service is started but does not immediately go to the background so leave it
running and open a different terminal in another tab or window.
[4] In the new terminal login to the mysql database with a password (usually) by typing mysql.
code:

# mysql <ENTER>

This should log you in automaticaly i.e you should see this kind of prompt mysql>,some
instruction and probably the MySQL version in my case (5.0.67)

[5] Now we are logged in our database to change the root pasword we have use one of the
default databases to list them,

code:

# show databases ; <ENTER>

You should see a database named mysql to use it

code:

# use mysql ; <ENTER>

See every thing is ok or so it seems

[6] Finaly its time to change the password simply do this

code:

 # update user set Password=PASSWORD('your_new_password_here') WHERE user='root';

to flush the privileges

code:

 # flush privileges ;

finaly exit

code:

 # exit ;

[7] Now kill whatever is related to what we have been talking about i.e( ps -e | grep mysql)
eg mysqld-safe and or mysql if not already dead i.e (kill -9 <PID>)

YOU ARE NOW FREE TO LOGGIN INTO YOU DATABASE AS root# THE ORDINARY WAY

code:

 # mysql -u root -p <ENTER>

password: ************* <ENTER>

and you are done

NB:I have not Tried this a Windows installation of mySQL try it I think it should     work just make sure that mysqld.exe and mysql.exe are in your path! Well you     can also start mysql with a txt file having the following code.

code:

update user set Password=PASSWORD('your_new_password_here') WHERE user='root';
flush privileges;

(these two should be in separate lines)
you are done and don’t “forget” your password again!?

brought to you  courtesy of ch1m3ra & JLUG
+++++++++++++++++++++++++++=====END====+++++++++++++++++++++++++++++++++
========================================================================

  1. No trackbacks yet.

Leave a comment