Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

mysql
error

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

Fahad Farid

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.

svg viewer

If the error persists, follow these commands:

  1. Stop the mysql daemon by typing:
mysql stop
  1. Start mysql without any privileges using:
mysqld_safe --skip-grant-tables &
  1. The terminal will stop responding. Open a new terminal and type:
mysql -u root
  1. 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.

  1. Exit the shell:
mysql> quit
  1. Restart mysql by typing:
kill -KILL [PID of mysqld_safe]
kill -KILL [PID of mysqld]
service mysql start
  1. Retry logging in by typing:
mysql -u root -p password

RELATED TAGS

mysql
error

CONTRIBUTOR

Fahad Farid
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring