Getting Lost MySQL Root Password

Its probably happened to everyone at one time or another, in the set up of a new box, forgetting what the heck you set that MySQL root password to. All is not lost, as long as you have root on your linux box! This is on a Red Hat box, your mysql start/stop commands may very by distro.

How to reset that root password:

Switch to root on box

Verify MySQL is running

ps aux | grep mysqld

If it is running kill it using the command below as it should provide a cleaner exit than killing the pid

/sbin/service mysqld stop

Now restart the mysqld process skipping over the grant tables

mysqld_safe –skip-grant-tables

Now verify mysqld started up again, if it didn’t you have bigger problems

ps aux | grep mysqld

If it is running connect as root, no password needed since we skipped the grant tables

mysql –user=root mysql

Now update the root password

UPDATE user SET Password = PASSWORD(‘new-password’) WHERE User = ‘root’;

Flush the privileges and exit

Flush privileges

Exit

Now kill the mysqld process

/sbin/services mysqld stop

Verify it stopped

ps aux | grep mysqld

Now start it back up again

/sbin/services mysqld start

Verify your new password

mysql –u root -p

If it is running kill it using the command below as it should provide a cleaner exit than killing the pid

/sbin/service mysqld stop

Now restart the mysqld process skipping over the grant tables

mysqld_safe –skip-grant-tables

Now verify mysqld started up again, if it didn’t  you have bigger problems

ps aux | grep mysqld

If it is running connect as root, no password needed since we skipped the grant tables

mysql –user=root mysql

Now update the root password

UPDATE user SET Password = PASSWORD(‘new-password’) WHERE User = ‘root’;

Flush the privileges and exit

Flush privileges

Exit

Now kill the mysqld process

/sbin/services mysqld stop

Verify it stopped

ps aux | grep mysqld

Now start it back up again

/sbin/services mysqld start

Verify your new password

mysql –u root -p

Now you should be in business!!

If it is running kill it using the command below as it should provide a cleaner exit than killing the pid

/sbin/service mysqld stop

Now restart the mysqld process skipping over the grant tables

mysqld_safe –skip-grant-tables

Now verify mysqld started up again, if it didn’t you have bigger problems

ps aux | grep mysqld

If it is running connect as root, no password needed since we skipped the grant tables

mysql –user=root mysql

Now update the root password

UPDATE user SET Password = PASSWORD(‘new-password’) WHERE User = ‘root’;

Flush the privileges and exit

Flush privileges

Exit

Now kill the mysqld process

/sbin/services mysqld stop

Verify it stopped

ps aux | grep mysqld

Now start it back up again

/sbin/services mysqld start

Verify your new password

mysql –u root -p

Comments are closed.

-->