9

I use the command php artisan migrate to migrate my database connection but I still get the same error and I checked everything, nothing wrong. I used the same connection that I always use in Laravel 4.2

Here is the message I get on my console:

exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)' in C:\xampp\htdocs\Projects\blog\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:47
dayuloli
  • 16,205
  • 16
  • 71
  • 126
Gaetan Sobze
  • 225
  • 2
  • 5
  • 13
  • Please post your database.php with the connection settings (with passwords xxx) – baao Feb 08 '15 at 02:08
  • @michael 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'root'), 'username' => env('DB_USERNAME', ' '), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ], – Gaetan Sobze Feb 08 '15 at 02:15

8 Answers8

20

You need to change the values in your .env file, located in the root folder of your project.

If there is no .env file, copy the .env.example file to .env.

Laravel uses this file to protect your passwords. The values as you are setting those are only used if there is no configuration available in the .env file, homestead is the standard user there.

baao
  • 71,625
  • 17
  • 143
  • 203
  • Wow...! `.env` file was not visible in my netbeans project (wonder) than find in browser and done.. Thanks...! – Code Lover Mar 23 '15 at 05:13
7

Take a look at your config/database.php and .env file.Maybe your database information is different.

6

You can go to .env file. File available on Project Root folder.

Then some here related to your database.

enter image description here

Then run below command to clear the old configuration cache.

php artisan config:clear

Pavnish Yadav
  • 2,728
  • 3
  • 15
  • 14
5

Have this problem as well. After update .env and run php artisan config:clear problem still persisted! Then after stoping the server and restart the server again with php artisan serve, problem fixed!

ken
  • 13,869
  • 6
  • 42
  • 36
1

Change the following attribute from 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,
]

to

 'mysql' => [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'laravel',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

This must work well then run the following command:

php artisan migrate:install
JJJ
  • 32,902
  • 20
  • 89
  • 102
1

I solve this issue by update .env file with config/database.php file.

here is my config/database.php structure (I am using mysql)

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

And .env file structure (same like config/database.php)

 DB_HOST=localhost      // Host name
 DB_DATABASE=larablog   // Database name
 DB_USERNAME=root       // Database User
 DB_PASSWORD=           // Db password(No password here) 
Jakir Hosen Khan
  • 1,498
  • 1
  • 14
  • 17
1

i was getting same error after updating database info in my .env file. fixed the problem exit command prompt and re run php artisan serve command it helped me out and might helpful for you.

zeeshan
  • 31
  • 6
0

If you're using sqlite as the database, make sure you've php5-sqlite installed

sudo apt-get install php5-sqlite

If it's installed, it might be a problem with your .env file. Replace

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

with this

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
Divyanshu Maithani
  • 13,908
  • 2
  • 36
  • 47