close

[Solved] Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user ‘forge’@’localhost’ (using password: NO)

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user ‘forge’@’localhost’ (using password: NO) in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user ‘forge’@’localhost’ (using password: NO) Error Occurs?

Today I get the following error Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user ‘forge’@’localhost’ (using password: NO) in php.

How To Solve Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user ‘forge’@’localhost’ (using password: NO) Error ?

  1. How To Solve Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) Error ?

    To Solve Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) Error The settings in .env are not always used for some reason or other and occasionally Laravel will just use the default settings in config/app.php and config/database.php.

  2. Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

    To Solve Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) Error The settings in .env are not always used for some reason or other and occasionally Laravel will just use the default settings in config/app.php and config/database.php.

Solution 1

Just cache your config using

php artisan config:cache

Don’t forget to do this every time after setting your .env file.

Solution 2

I had this exact same problem for the past few days and I think I solved it:

The settings in .env are not always used for some reason or other and occasionally Laravel will just use the default settings in config/app.php and config/database.php.

config/app.php:

'key' => env('APP_KEY', 'SomeRandomString'),

'cipher' => 'AES-256-CBC',

Change the ‘SomeRandomString’ to the generated key from your .env

config/database.php

'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

Change localhost, database, username, password to your actual settings from the .env. This example is for MySQL if you use another database, change those variables instead.

There might be a better solution (more secure?) but this is what so far kept the error from showing up.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment