Wednesday, November 24, 2010

I lost/forgot mysqld root password

Oops, it happens, you install quickly set a good password then promptly forget to record it.
What a pain, but easily remedied using the command line!
  1. stop mysqld
    service mysqld stop 
  2. create a text file for example mysqld.reset.password containing the following 2 lines
    update mysql.user set password=password('yournewpassword') where user='root';
    flush privileges;
  3. load mysqld using the text file as input
    mysqld_safe --init-file ~/mysqld.reset.password
  4. delete your text file, for cleanliness & security reasons
    rm ~/mysqld.reset.password
  5. start mysqld
    service mysqld start