Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

macos

I'm trying to reinstall mysql on my MAC OS X Yosemite. for this I followed the instruction as mentioned below

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/MySQL*
vim /etc/hostconfig and removed the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/MySQL*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*

I also tried

brew uninstall mysql

after this I installed mysql using homebrew using command brew install mysql. After installation when I tried to run mysql -u root It throws the following error

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

I didn't set password for mysql.I don't know what's going wrong.Any suggestion will be appreciated. Thank you

like image 486
Bibek Sharma Avatar asked Sep 30 '15 05:09

Bibek Sharma


People also ask

How do I fix error 1045 28000 Access denied?

Set root user password Login as user root with blank password >mysql -u root mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc';

How do I fix error 1045?

The #1045 error is a phpMyAdmin authentication error that can be caused by an incorrectly typed username or password. To troubleshoot this error, you should complete a password reset and make sure you're using the correct database host name.

How do I fix MySQL access denied error?

To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password'; Replace user_name with the user's username and password with the user's password.

How do I fix localhost Access Denied?

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.


2 Answers

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
$ sudo pkill mysqld
$ sudo rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot
like image 73
Ghrua Avatar answered Sep 27 '22 21:09

Ghrua


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';
like image 37
Inês Gomes Avatar answered Sep 27 '22 19:09

Inês Gomes