익명 06:26

SQLSTATE[HY000] [1045] Access denied for user

SQLSTATE[HY000] [1045] Access denied for user

I have started my first website (in development) with a simple authentication structure. When I run my website with Homestead, database connection does not work. Actually I can run any mysql command from terminal or mysql workbench, but when I try from browser (homestead.app), I get this error:

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

Here my .env information:

DB_CONNECTION=mysql 
DB_HOST=localhost
DB_PORT=3306 
DB_DATABASE=homestead
DB_USERNAME=homestead 
DB_PASSWORD=secret

I changed the permission and restarted server but same result!



Top Answer/Comment:

This is because you did not grant access to that specific user on localhost. To remedy this, use this:

  1. Enter MySQL (watch out: root here is the MySQL root, NOT the ubuntu root - you could also use other users having sufficient access level):
$ mysql --user=root --password=root_password homestead
  1. In MySQL, grant access like this (in this case, create the user 'homestead'@'localhost' and give him select privileges on everything from DB homestead):
CREATE USER 'homestead'@'localhost' IDENTIFIED BY 'secret';
GRANT SELECT PRIVILEGES ON homestead.* to 'homestead'@'localhost' IDENTIFIED BY 'secret';

Refer to the MySQL manual for more info on other options.

This being said, you might preferably post such questions on other sites dedicated to DB administration.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다