Deedub Deedub - 5 months ago 28
MySQL Question

Stuck with Access Denied for user 'root'@'localhost' - Terminal, Mac

I am stuck when trying to access mysql. It's my first time so please be patient with me.

Initially I was try to set up Ruby and Rails and everything worked perfrectly expect access denied when connecting to the server, SO I ran this command.

mysql -uroot -p

I've tried various passwords including leaving it blank and get this error.

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I am assuming I need to reset the password for root user but I just can't seem to get it to work.

Answer Source

One method:

  1. stop your MySQL server.
  2. start your MySQL server with the --skip-grant-tables option. It allows you to connect to the server without a password.

    /path/to/mysqld --skip-grant-tables &

  3. connect to your server using the mysql client:


  4. change the root password (replace NewPassord by what you want):

    UPDATE mysql.user SET password=PASSWORD('NewPassord') WHERE user='root';

  5. restart yout MySQL server.

There are others ways to reset the MySQL root password:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download