Laravel: SQLSTATE HY000 2002 无法建立连接,因为目标机器主动拒绝它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36425420/
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
Laravel: SQLSTATE HY000 2002 No connection could be made because the target machine actively refused it
提问by Arthur Tarasov
I am trying to migrate migrations to MySQL database using php artisan migrate
in Laravel 5.2's Homestead on my local machine. I keep getting this error:
我正在尝试php artisan migrate
在本地机器上使用Laravel 5.2 的 Homestead将迁移迁移到 MySQL 数据库。我不断收到此错误:
[PDOException]
SQLSTATE[HY000] [2002] No connection could be made because the target machine
actively refused it.
I can connect to the database just fine using MySQL workbench, but I want to use laravel's migration feature.
我可以使用 MySQL 工作台很好地连接到数据库,但我想使用 laravel 的迁移功能。
My database.php
looks like this:
我的database.php
看起来像这样:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '192.168.10.10'),
'port' => env('DB_PORT', '33060'),
'database' => env('DB_DATABASE', 'laraveldb'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
Has anyone had this problem before?
以前有人遇到过这个问题吗?
回答by Alexey Mezenin
Use these default settings in your .env file:
在 .env 文件中使用这些默认设置:
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Also, be sure homestead
database is created.
另外,请确保homestead
已创建数据库。
The thing is .env
settings override database.php
ones.
事情是.env
设置覆盖database.php
的。