As a system administrator, there are always an embarrassed occasion that your superuser password is forgot.

Without a root password, how you can recover?

Here I consolidate my experience in dealing with this specific issue on a variety of systems.

MySQL

  • stop mysql first
  • start a safe mode with option
    • mysqld_safe --skip-grant-tables &
  • update mysql.user table for user ‘root’ via mysql client
    • UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
  • stop safe mode and start normal mysqld