Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

terminal

mysql

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.

like image 523
Deedub Avatar asked Sep 17 '14 16:09

Deedub


People also ask

How do I fix error Access denied for user root localhost?

Use the ALTER USER command and change the authentication method to log into MySQL as root: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password'; This command changes the password for the user root and sets the authentication method to mysql_native_password.

How do I fix root access denied?

If you get the “access denied” error, one way to solve it is by using sudo to log in to mysql and change the root password.


2 Answers

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:

    mysql
    
  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: http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html

like image 55
Muur Avatar answered Sep 17 '22 22:09

Muur


I had a similar issue and this worked like a charm -

Later versions of mysql implement a newer authentication scheme, not all libraries are up to date with this. You can revert to classic authentication by adding the following entry into your my.cnf

[mysqld]

# Only allow connections from localhost
bind-address = 127.0.0.1

# Some libraries not compatible with latest authentication scheme as per the SO article [1].
default-authentication-plugin=mysql_native_password

Simply add the following in /private/etc/my.cnf

# Only allow connections from localhost
bind-address = 127.0.0.1

Reference: https://www.reddit.com/r/mysql/comments/ae7rf4/access_denied_for_user_rootlocalhost_mac_os/

like image 33
AmolR Avatar answered Sep 21 '22 22:09

AmolR