Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

I've tried multiple solutions from StackOverflow but haven't had any success. I'm on Mac OSX (Sierra 10.12.3) trying to create a new database and user. From terminal I enter:

mysql -u root 

which outputs this error:

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

To try and resolve it I stopped mysql from 'System Preferences', then from terminal typed:

sudo mysqld_safe —skip-grant-tables 

I opened a second tab and entered:

mysql -u root 

Then from in mysql:

update mysql.user set password_expired = 'N', authentication_string=PASSWORD('newpassword') where user = 'root';  flush privileges; 

I then restart the computer (killing the process with CMD + C doesn't work). After restarting, trying mysql -u root still produces the same error.

I am able to access mysql via a MySQL client and a non-root user.

Any help is appreciated.

like image 389
Alan P. Avatar asked Mar 11 '17 23:03

Alan P.


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 MySQL 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.


1 Answers

For security reason mysql -u root wont work untill you pass -p in command so try with below way

 mysql -u root -p[Enter]  //enter your localhost password 
like image 97
Pramod Patil Avatar answered Oct 14 '22 05:10

Pramod Patil