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

I installed mysql with homebrew and got the same problem as you because mysql has had an existing database with an existing password there. See this article for more details.

$ 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

Now sql generates an aliatory password that appears in the last screen.

sudo mysql -u root -h 127.0.0.1 -p
Enter password: (aliatory password)

we can change it

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';

I have resolved this issue for myself.

Please check my github with this link: https://github.com/LeVanTuan/access_sql

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

Fix bug access denied on macos 10.12 (Sierra)

install mysql (https://dev.mysql.com/downloads/mysql/) if already installed, skip this step

Update password of 'root' to access.

Open Terminal (Launchpad -> Other -> Terminal or (Command + space) -> Type 'terminal' )

Then type follow below:

export PATH=$PATH:/usr/local/mysql/bin/

sudo mysqld_safe --skip-grant-tables

then, restart Terminal (quit then open again)

then, keep type:

export PATH=$PATH:/usr/local/mysql/bin/

mysql -u root mysql

FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

\q

sudo /usr/local/mysql/support-files/mysql.server start

extra: start mysql: sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables stop mysql: sudo /usr/local/mysql/support-files/mysql.server stop

I hope it will help you

Tags:

Mysql

Macos