在 Laravel 4 - SQLSTATE[HY000] [1045] 用户 'forge'@'localhost' 访问被拒绝(使用密码:NO)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24643629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Laravel 4 - SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)
提问by user3733120
I get this error in Laravel 4. My config/database.php file says,
我在 Laravel 4 中收到此错误。我的 config/database.php 文件说,
'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.
早些时候我将环境更改为生产环境,然后现在更改为本地环境。
回答by emartel
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.
如果您将环境更改为local
,则应检查database.php
文件\app\config\local\
夹中是否有文件。您的环境特定配置会覆盖\app\config\
文件夹中的全局配置。
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.
看到您的连接正在尝试使用 的forge
用户名localhost
,您刚刚发布的配置似乎被另一个配置文件覆盖。
回答by Y. Joy Ch. Singha
In database.php
在数据库.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
在 .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.
希望,这可能会奏效。谢谢。