Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost'

I am getting SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' error while running composer update command. My .env file settings is like below.

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=wolf DB_USERNAME=root DB_PASSWORD=root

I am getting below error.

https://i.stack.imgur.com/prMDe.png

0 likes
19 replies
Sinnbeck's avatar

So the error says you are using wrong username or password?

1 like
kokoshneta's avatar

@afoysal Clearly you didn’t, because as you can see in your screenshot, it’s trying to connect WITHOUT a password.

Also, it’s not composer update that’s causing the error (that doesn’t access your Laravel database). It’s Laravel’s ‘discover packages’ script that is set to run after Composer’s update script.

If you don’t need the package discovery script – and often you don’t actually – you can just remove it from your composer.json file.

1 like
afoysal's avatar

@kokoshneta Thanks. How can I remove it from composer ? Should I remove it from here ? "scripts": { "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" ] }

kokoshneta's avatar

@afoysal Yes, exactly. At least, I’ve found that removing , "@php artisan package:discover --ansi" from my Composer file had no ill effects.

1 like
tykus's avatar

Is your config cached?

php artisan cache:clear
1 like
tykus's avatar

@afoysal you are probably making a database call in a ServiceProvider (which calls to your helpers file on line 183) - if you can wrap whatever that code is like this:

if (!app()->runningInConsole()) {
    // make the query
}

then you should be able to clear the incorrect cache

1 like
afoysal's avatar

@Sinnbeck Thanks . But I couldn't find that ServiceProvider. That's why I asked that. Thanks.

Sinnbeck's avatar

@afoysal Well you can open the helpers file and instead check on line 183. That is doing a database call which is being run on every single request (and cli call)

1 like
tykus's avatar

@afoysal maybe you don't understand the meaning of probably? Anyway, I told you where to look and what to do as mitigation, so good luck with that 👍

1 like
kokoshneta's avatar

@afoysal So look on line 32 in your AppServiceProvider as the error message is telling you to…

1 like
tykus's avatar

@afoysal are we to direct you through every line in the stacktrace?

chahal's avatar

Are you using MAMP? Please confirm you are using the correct port.

Is 3306 the correct port?

Please or to participate in this conversation.