Wednesday, September 14, 2011

Reset MySQL root password


  • Kill the mysql process using. Some process has may not be in the folder in the example below. The folder can be found my using ps aux | grep mysqld and looking for the file that ends with .pid or starts with mysqld
    • $: kill `cat /var/run/mysqld/mysqld.pid`


  • Create a file with entries below.
    • UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';

    • FLUSH PRIVILEGES;


  • Start mysql using the command below. Where --init-file is the path to the file created above.
    • mysqld_safe --init-file=/home/me/mysql-init &


  • Login to mysql using the new mysql root password

MySQL root password should be reset now.

Reference: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-unix