问题
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
回答1:
Take a look at your config/database.php and .env file.Maybe your database information is different.
回答2:
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.
回答3:
You can go to .env file. File available on Project Root folder.
Then some here related to your database.

Then run below command to clear the old configuration cache.
php artisan config:clear
回答4:
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!
回答5:
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
回答6:
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)
回答7:
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.
回答8:
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
来源:https://stackoverflow.com/questions/28389697/problems-with-database-connection-in-laravel-5