简体   繁体   中英

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)?

在此处输入图像描述 .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=task
DB_USERNAME=root
DB_PASSWORD=******

List of all databases mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | nodeDB | | performance_schema | | phpmyadmin | | pythonDB | | sys | | task | +--------------------+ 8 rows in set (0.13 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | nodeDB | | performance_schema | | phpmyadmin | | pythonDB | | sys | | task | +--------------------+ 8 rows in set (0.13 sec)

Already tried these solutions

SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)

Access Denied for User 'root'@'localhost' (using password: YES) - No Privileges?

If you are able to login to mysql console. Then try printing the Mysql Users by the following commands.

SELECT user,authentication_string,plugin,host FROM mysql.user;

If you find root has a plugin of type auth_socket , then either you need to change it to mysql_native_password by the following command.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Do not forget to replace the password with your password.

Then Flush Privileges by using FLUSH PRIVILEGES;

Alternatively, you can create another user and grant privileges.

CREATE USER 'ankush'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'ankush'@'localhost' WITH GRANT OPTION;

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