TransWikia.com

SQLSTATE[HY000] [1045] Access denied for user

Ask Ubuntu Asked by yyusufaslan on December 31, 2021

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!

One Answer

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.

Answered by Marc Vanhoomissen on December 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP