Reset lost root password in MySQL

This is a handy procedure that can be used to reset the root password for the MySQL account. I had to use this procedure on a failed installation. It appeared that I had a problem with the bin/install_db command, and it failed to pre-populate the mysql.user table with the correct initial permissions and grants. Without this information, I was dead in the water. I had an empty grant / access table so I couldn’t log in.

The following sequence was taken to correct this problem:

  1. stop the server

    /etc/init.d/mysql.server stop

  2. start the server, but tell it to skip the grant tables

    /opt/mysql/bin/mysqld_safe –skip-grant-tables &

  3. login as root user

    /opt/mysql/bin/mysql -u root -p

At this point, you should be able to change passwords. In my case, I needed to rebuild the initial database schema and user tables. I removed the mysql database and re-ran the install_db –user=mysql command. Following that, I was good to go.