Reset mysql root password

Sharing the root password is a suicide, somebody changed the password today 😦
Here are the steps to reset it.

Ref: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

I will explain the steps in ubuntu!

 

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

login as the user, who is running mysql

Generally the username would be mysql.

$su
#su - mysql
$

Stop the mysql service

$service mysql stop

Create a new file with the following contents

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

you need to execute this commands using safemode

root@ubuntu250:/var/lib/mysql# mysqld_safe --init-file=mysqlpasswd &

You will see the server is starting as below

[1] 2901
root@ubuntu250:/var/lib/mysql# 120106 21:35:48 mysqld_safe Logging to syslog.
120106 21:35:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

login now with the new password. it should work now.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s