Resetting a Lost MySQL Password

I sometimes use a Debian Ubuntu VMWare build to do some LAMP development. Due to my inexperience administering anything having to do with Linux, while trying to reset the root password, I accidentally put in some bad information into the password field (I forgot to use the password() function to generate encrypted password text), and ended up being locked out of the DB. After wading through a dozen different pages giving advice on how to reset a lost MySQL root password, I ended up finding a solution that worked for me:

  1. In terminal window with root access (in my case, using the sudo su command)
  2. # killall mysqld
  3. # mysqld –skip-grant-tables –user=root &
  4. Open new terminal window with root access
  5. # mysql (I am now logged into mysql as root)
  6. mysql> use mysql
  7. mysql> update user set password = password(“NEWPASSWORD”) where user=”root”;
  8. mysql> flush privileges;
  9. mysql> exit;
  10. # killall mysqld
  11. # /etc/init.d/mysql start

Definitely a relief to be able to successfully log back in again (and a good thing that this happened to me on my private test box and not on the public testing server).

Tagged , , , . Bookmark the permalink.

Leave a Reply

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