user3733120
user3733120

Reputation: 55

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

I get this error in Laravel 4. My config/database.php file says,

'connections' => array(

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => '127.0.0.1',
        'database'  => 'my-site-name',
        'username'  => 'my-site-name',
        'password'  => 'my-password',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

Earlier I changed my environment to production, then now to local.

Upvotes: 1

Views: 18371

Answers (2)

Y. Joy Ch. Singha
Y. Joy Ch. Singha

Reputation: 3252

In database.php

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

In .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_db_name
DB_USERNAME=your_db_user_name
DB_PASSWORD=your_db_password

hope, this may work out. Thanks.

Upvotes: 0

emartel
emartel

Reputation: 7773

If you changed your environment to local, you should check if you have a database.php file located in your \app\config\local\ folder. Your environment specific configurations override the global ones from your \app\config\ folder.

Seeing as your connection is trying to use the forge username for localhost, it seems like the configuration you just posted is being overwritten by another config file.

Upvotes: 4

Related Questions