jackbaron's avatar

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

I'm working with Laravel, and everything is fine so far. But sometimes, when I request a webpage, an error occurs :

🧨 SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

I don't understand why and when this error occurs, it seems very random (~5%), and reloading the page fix it. My .env file looks like this :

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydatabase
DB_USERNAME=my_username
DB_PASSWORD=password_strong

Where does this user 'forge' come from ? I never had one. I tried php artisan config:clear and php artisan cache:clear but I still get the error times to times.

Note : I'm saying that this error seems to be random because I use Ajax to load some subPage in my main page. And sometimes one of theses elements fail to load with this error, but not everytimes and not always the same.

i think problem in the AppServiceProvider. i had a query i used in the boot function. I think this was trying to executed a query before env file loaded.

0 likes
7 replies
jackbaron's avatar

@Sinnbeck thank for reply.

If you change it in the config file in your own project, does the error chance? i will try this and check if when have the result i will notify you

is there any other way. because I don't removed it for the time being

Sinnbeck's avatar

@jackbaron Sorry I dont quite understand what this means

because I don't removed it for the time being

Sinnbeck's avatar

As Snapey asked, is this production or? If so, what is your setup?

Andi1982's avatar

@jackbaron virtual server? php-fpm or as apache-mod?

could really be a caching problem, so maybe .env is going out of cache and filesystem not delivering fast enough. But then also other-settings from .env should be missing, not just DB-connection-data.

Snapey's avatar

this would imply that sometimes your .env is not being read properly. What system is this, local dev or production. If production, caching the config would help

1 like

Please or to participate in this conversation.