Monday 15 April 2013

Reset MySQL Root Password



There are times when we forget our Root password and that can be troublesome. And because we can't reset it or don't know how to reset it, we tend to erase everything and format it.

However, I will show how to reset MySQL Root password in Linux Operating System. Its fairly, simple and not very long process to conquer it.

Let's stop MySQL daemon that's running.

# /etc/init.d/mysqld stop

Now, we need to start again MySQL but skip the grant tables which store the passwords that way we don't need to provide Root password and we can proceed on with reseting with new password.

# mysqld_safe --skip-grant-tables

you'll see something like this

130415 09:57:29 mysqld_safe Logging to '/var/log/mysqld.log'.
130415 09:57:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql


if you get stuck then just press ctrl + z

Now, hopefully it should be up and running, do check using netstat and you'll see mysql daemon running

# netstat -tnlp

let's proceed with logging in and reseting new password.

# mysql --user=root mysql


mysql> update user set Password=PASSWORD('new-password') where user='root';
mysql> flush privileges;
mysql> exit;


# /etc/init.d/mysqld stop OR Kill the process
# /etc/init.d/mysql restart

Tada, check it and you'll see that you have successfully changed MySQL Root password

Enjoy Amigos



No comments:

Post a Comment