[英]Laravel Homestead SQLSTATE[HY000] [2002] Connection refused after server move
I moved an application that I'm working on into a new dev server, a Laravel Homestead VagrantBox on a Mac OSX host. 我将正在处理的应用程序移至新的开发服务器,即Mac OSX主机上的Laravel Homestead VagrantBox。 Upon doing so, I ran php artisan:migrate to update my database and this went through without a hitch.
这样做之后,我运行了php artisan:migrate来更新我的数据库,并且一切顺利。
I decided to create a new user to continue testing, so I created the route 我决定创建一个新用户以继续测试,因此我创建了路由
Route::get('/newuser', function()
{
User::create([
'username' => 'someone',
'email' => 'someone@someone.com',
'password' => Hash::make('password')
]);
return 'Done.';
});
When I visit /newuser, however. 但是,当我访问/ newuser时。 I am getting the following message.
我收到以下消息。
SQLSTATE[HY000] [2002] Connection refused
Now, I know that my database config must be correct, as I received no errors when I ran php artisan migrate and my database migrated successfully. 现在,我知道我的数据库配置必须正确,因为当我运行php artisan migration并成功迁移数据库时没有收到任何错误。 However, just to be safe, I checked my database config.
但是,为了安全起见,我检查了数据库配置。
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost:33060',
'database' => 'site',
'username' => 'root',
'password' => 'apassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I figured that maybe there was an issue with the way I defined the port I was on, so I added the parameter: 我发现也许定义端口的方式存在问题,所以我添加了参数:
'port' => '33060'
Upon doing this, the error message changed from "Connection refused" to "No such file or directory" 执行此操作后,错误消息从“连接被拒绝”更改为“没有这样的文件或目录”
I'm at a loss. 我很茫然。 Does anyone have any pointers?
有人有指针吗?
Now, I know that my database config must be correct, as I received no errors when I ran php artisan migrate
现在,我知道我的数据库配置必须正确,因为运行php artisan migration时没有收到任何错误
It's a better than even money bet when you're stuck on something that it's one of your assumptions that's the problem. 当您坚持认为是问题的一种假设时,这甚至比赌钱要好。 It's possible your Laravel application is reading different credentials during a command line run, or that the migration had nothing to do, or for some weird PHP reason the errors were suppressed during your migration run.
您的Laravel应用程序可能在命令行运行期间读取了不同的凭据,或者迁移无所事事,或者由于某些怪异的PHP原因而导致错误在迁移运行期间被抑制。 I'd check the credentials Laravel's using during the context your errors are cropping up.
我会在出现错误的情况下检查Laravel使用的凭据。 Add the following code to your
newuser
route to see what Laravel's reading. 将以下代码添加到您的
newuser
路由中,以查看Laravel的读物。
$default = Config::get('database.default');
var_dump($default);
$config = Config::get('database.connections.'.$default);
var_dump($config);
I had same problem and i saw my database server was unresponsive i restarted and it works... sometime it cause when wrong configuration. 我遇到了同样的问题,我看到我的数据库服务器无响应,我重新启动后就可以工作了……有时会导致错误的配置。
I posted this answer if someone will have same issue and mysql unresponsive :) 如果有人会遇到相同的问题并且mysql无法响应,我会发布此答案:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.