1
mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I am unable to find the solution for this.

1
  • Is any answer a solution Nov 12, 2019 at 14:10

2 Answers 2

0

Just run

mysql -u root

This will not prompt for a password.

1
  • It shows the same error 1045. Feb 21, 2019 at 15:54
0

According to the official docs there are multiple cases:

  1. There was set a random password during installation

    • Initialize the data directory if it wasn't during installation: mysqld --initialize
    • Get the generated password by looking in the error log: cat /var/log/mysql/error.log | grep root@localhost
    • Log in with that password: mysql -u root -p (in some cases you have to run this with sudo)
    • Change the password: ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
  2. There was not set a random password during installation

    • Initialize the data directory if it wasn't during installation: mysqld --initialize-insecure
    • Log in with that password: mysql -u root --skip-password (maybe you have to try also with sudo)
    • Change the password: ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Hope that helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .