Reset MySQL root password

Sometimes you do not remember a password anymore. Like me just before. I cannot remember the root password of the one MySQL database. Well, that is not really a problem. You can easily recover it, if you got root access to the machine with the following steps:

  1. Log into the system as root
  2. Stop MySQL like
    /etc/init.d/mysql stop
  3. Create a file, e.g. /tmp/reset, with the following content:
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
  4. Execute the next command:
    mysqld_safe --init-file=/tmp/reset
  5. Restart MySQL:
    /etc/init.d/mysql restart
  6. Remove the temporary file:
    rm /tmp/reset