When this Error comes :
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Here is a simple way to fix mysql Access which is denied for user 'root'@'localhost' ( use below command )
mysql -u root -p
Enter password: my_password
If you lost your mysql password or get locked by extra command used in past. Then this is the last option you can try
/etc/mysql/debian.cnf (file location)
or through command line : sudo cat /etc/mysql/debian.cnf
Then you will find default details like below -
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = KbgKUX4usUDEA2 socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = KbgKUX4usUDEA2 socket = /var/run/mysqld/mysqld.sock
mysql -u debian-sys-maint -p
Enter password:
now provide password (KbgKUX4usUDEA2).
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewPassword';
Replace 'NewPassword' with your password above in SQL query.
FLUSH PRIVILEGES;
mysql -u root -p
Enter password:
Now provide new password which were created using SQL Query. That's all, we have new password for further uses.
It worked Well, hope it will help!