'Access denied for user 'root'@'localhost'

  1. Open & Edit /etc/my.cnf
    Add skip-grant-tables under [mysqld]
  2. Restart Mysql
  3. You should be able to login to mysql now using the below command mysql -u root -p
  4. Run mysql> flush privileges;
  5. Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
  6. Go back to /etc/my.cnf and remove/comment skip-grant-tables
  7. Restart Mysql

Now you will be able to login with the new password mysql -u root -p