Thursday, June 09, 2005

mysql Forgoten Password

This Sheet describes the procedure how to change the root password of MySQL server.

  1. Stop MySQL server if its running.

    # service mysqld stop

  2. Check that MySQL daemon has stopped

    # ps -jef | grep mysqld

  3. Start MySQL as root

    # su -
    # /usr/libexec/mysqld -Sg --user=root &

  4. Go back into MySQL with the client:

    # mysql
    mysql> use mysql

  5. Now change the MySQL root password

    mysql> UPDATE user SET password=password("newpassword") WHERE user="root";

    mysql> flush privileges;

    mysql> exit;

  6. Stop MySQL server.

    # killall mysqld

  7. Verify that MySQL daemon is not running

    # ps -jef | grep mysqld

  8. Start MySQL the normal way, and all is good. For Red Hat this is:

    # service mysqld start

  9. Verify if MySQL daemon is running

    # ps -jef | grep mysqld

    That's it.