MacOSX homebrew mysql root password

Alisher Ulugbekov picture Alisher Ulugbekov · Mar 14, 2012 · Viewed 105.3k times · Source

For some reason MySQL stopped giving access for root. Uninstalled and reinstalled with Homebrew. Fresh install, fresh tables but when I enter

mysql -u root -p

I get this error:

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

I reinstalled MySQL five times but it is still asking for a password. How do I fix this?

Answer

stackPusher picture stackPusher · Apr 22, 2018

None of these worked for me. I think i already had mysql somewhere on my computer so a password was set there or something. After spending hours trying every solution out there this is what worked for me:

$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot

all credit to @Ghrua