当我的 .env 文件是这样的:
DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
终端php artisan migrate
工作成功,但在本地主机测试中,它抛出 :PDOException in Connector.php line 50:
SQLSTATE[HY000] [2002] Connection refused
但是当我的 .env 文件是这样的:
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
在本地主机上,一切(注册)运行良好 php artisan migrate
在终端抛出:[PDOException] SQLSTATE[HY000] [2002] No such file or directory
我的 database.php 文件:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'port' => '33060',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
最佳答案
在 VM 内部,sql 端口是 3306。在 Homestead VM 之外,主机只转发到 Homestead VM 上的 SQL 端口。这就是为什么 33060 指向 3306。
Laravel Homestead Vagrant Box Database Problems
关于mysql - Laravel 5.1 - Homestead MySQL 连接。 `Connection Refused` & `No such file or directory`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31926383/