All Articles

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

unsplash-film

Accessing MySQL local user failed. As always, figuring out the cause of the error is the key to the solution. The error message "using password:NO"confused me because I thought this has something to do with MySQL password.

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

What I didn’t catch in the error was that I might not create MySQL id in the first place. Follow the below steps to check if you actually create your user id.

mysql -u root -p
Enter password

mysql> use mysql;
mysql> select user, host from user;
    +------------------+-----------+
    | user             | host      |
    +------------------+-----------
    | bill             | localhost |
    | debian-sys-maint | localhost |
    | mysql.session    | localhost |
    | mysql.sys        | localhost |
    | root             | localhost |
    +------------------+-----------+
 5 rows in set (0.00 sec)

See if you have your MySQL user id. If not, you bascially created your new user id.

  1. Create a new user
    mysql> create user 'test'@'localhost' identified by '1111';
    Query OK, 0 rows affected (0.00 sec)

    mysql> grant all privileges on test_database.* to test@'localhost';
    Query OK, 0 rows affected (0.00 sec)
  1. Grant Privileges
mysql> grant all privileges on test_database.* to test_grant@'localhost' identified by '1111';
Query OK, 0 rows affected (0.00 sec)
  1. Change Password
mysql> UPDATE user set authentication_string=password("my_password1111") WHERE user = 'test';
Query OK, 1 row affected (0.00 sec)
mysql> flush privileges;
  1. Delete MySQL
mysql> delete from user where user='test';
Query OK, 1 row affected (0.00 sec)

mysql> delete from user where user='test_grant';
Query OK, 2 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

We are creating wealth every time we write a code