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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top