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

packy's avatar
Level 7

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

This is my 5th site with forge and the first time this has ever happened. I keep getting the error when connecting my repository to my default app:

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

I changed my .env file in my forge app to:

APP_NAME="My Site"
APP_ENV=local
APP_KEY=XXXXXXXX
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://mystie.com

FILESYSTEM_DRIVER=public

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=XXXXXXXXXXXXXXX <-the emailed password

I have successfully SSh in with SQL Pro so I know the credentials work.

I have not changed the database config file:

 'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

It looks like the error happens on Script php artisan optimize handling the post-install-cmd event returned with error code 1

I have never had a bad install yet, and things run super smooth. Now on about 2 hours trying to figure out why this one went bad.

0 likes
4 replies
jlrdw's avatar

Looks right are you sure a server wasn't down for a while?

packy's avatar
packy
OP
Best Answer
Level 7

Okay so I figured it out. Not sure why but in my AppServiceProvider I had a query I used on boot:

 $locations = Location::get();
 View::share('locations', $locations);

I think this was trying to ping the db before migrations were run so it failed every time.

Please or to participate in this conversation.