Resetting a MySQL root password

It happened, I forgot a password. I normally pride myself on my memory for things like passwords but this one was gone so I went searching for a way to reset it. I found this very concise entry at that sorted me out. There were many others like it but this is the one that I followed to reset the password (it’s also written by a guy that works for the hosting company I use, Bytemark)

In short my own version of the process:

  1. Stop the MySQL process.
    /etc/init.d/mysql stop
  2. Start MySQL manually with the –skip-grant-tables parameter.
    /usr/bin/mysqld_safe --skip-grant-tables &
  3. Run MySQL from the command line, logging in as root with no password.
    mysql --user=root --pass mysql
  4. Update the user table, setting the root user’s password.
    UPDATE User set Password=PASSWORD('newpass') WHERE User = 'root';
  5. Flush the privileges cache.
    flush privileges;
  6. Exit MySQL.
  7. Restart the MySQL service without skipping the privileges tables.
    /etc/init.d/mysql stop && /etc/init.d/mysql start