mysqlaccess-deniedmysql-error-1045

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


I know this question has been asked like a million times here but for the life of me I can't seem to figure out what's wrong. Would appreciate if someone can help me to troubleshoot.

I installed mysql using homebrew using brew install mysql.

No errors whatsoever. Then I tried to run mysql -uroot -p. This error appeared: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2). So I opened MAMP and started the server. Ran the same command again, but this time it was another error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

I downloaded Sequel Pro and tried to do a socket connection with the username root and no password. It worked so I guess the username and password is correct?

Any help please?


Solution

  • Issue was resolved in the comments:

    If you didn't do any additional setup for sequel pro, then adding -h 127.0.0.1 to your command should do the trick: mysql -u root -h 127.0.0.1: by default mysql client looks for a connection at default path, something like /tmp/mysql.sock, which isn't there because MAMP uses another location (/Applications/MAMP/tmp/mysql/mysql.sock')