Resetting MySQL root password

Somehow I got banned from own MySQL server installed on my Mac running OSX Moutain Lion. Every time I tried to log in as root (my only user) I would get: mysql access denied for user ”@’localhost’

Don’t know how I ended up in that situation, but write here how I got out, for others to know (and for me to remember). The deal is basically to reset the root password.

The solution is in this blog post:

Here are the step I followed with MySQL 5.5.28 running on OSX 10.8.3:

  • turn off mysql server
  • first terminal: sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables
  • second terminal:
    launch the admin console: /usr/local/mysql/bin/mysql mysql
    reset the password: UPDATE mysql.user SET Password=PASSWORD(“newpwd”) WHERE User=”root”; FLUSH PRIVILEGES;
  • turn on mysql server

EDIT : got stuck a couple of days later with the same problem and the same solution did not work. I used the little scripts provided there: