Access denied for user 'root@localhost' (using password: NO)
When you install MySQL and try to access it from your local machine as root, you may encounter this error.
Run the command
mysql -u root -p
When prompted for a password, you press enter. The process suggests that a password for root has not yet been set. However, you should set the password because running as root without a password has many security concerns.
If the error persists, follow these commands:
- Stop the mysql daemon by typing:
mysql stop
- Start mysql without any privileges using:
mysqld_safe --skip-grant-tables &
- The terminal will stop responding. Open a new terminal and type:
mysql -u root
- Enter the permission setting of the root user by typing:
mysql> use mysql;
mysql> select * from user;
mysql> flush privileges;
mysql> grant all privileges on *.* to root@localhost identified by 'Password' with grant option;
Enter your password in place of Password.
- Exit the shell:
mysql> quit
- Restart mysql by typing:
kill -KILL [PID of mysqld_safe]
kill -KILL [PID of mysqld]
service mysql start
- Retry logging in by typing:
mysql -u root -p password
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved