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

Try to log into the MySQL server, but it prompts the following error message:

Terminal

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

1. Solution – (using password: NO)

The user ‘root’ need a password to log into the MySQL server. To solve it, please provide a password with -p flag while connecting to MySQL server.


$ mysql -u root -p
Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

2. Solution – (using password: YES)

If you hits this (using password: YES) error :


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

This means you are provided an invalid password.

Note
Please read this Connecting to the MySQL Server
author image

mkyong

Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities. Read all published posts by

Comments

avatar