简体   繁体   中英

Access denied for user 'root'@'localhost' (using password: NO) for MySQL 8.0+

Initially mysql -u root was working fine.

Then I tried to reset root user password using below command

UPDATE set authentication_string=PASSWORD("password") where User='root';

But when I tried mysql -u root -ppassword it's throwing

access denied for user 'root'@'localhost' (using password: NO)

So to fix above solution do following steps:

  1. First search where your mysql scripts exist in your system using which mysql

/usr/local/bin/mysql

  1. run cd /usr/local/bin
  2. Then look for mysql.server file and execute mysql.server stop

output is:
Shutting down MySQL
. SUCCESS!

  1. run killall mysqld mysqld_safe
  2. run mysqld_safe --skip-grant-tables &
  3. Then try mysql -u root it will work

So next step is to update the root password back to <no-password>

  1. run use mysql;
  2. run Update user set authentication_string='' where User='root';

NOTE: To update mysql 8.0+ password, always use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM