连接尝试失败,连接方未正确响应
Connection Attempt Failed, Connected Party didn't Properly Respond
SQLSTATE[HY000] [2002] A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to
respond. (SQL: SELECT * FROM users)
我想在我的本地项目中连接到我的远程数据库,但是当我这样做时出现上面列出的错误。它在我的另一个数据库(来自本地主机)中工作,我如何连接我的远程服务器数据库?
database.php
'mysql2' => [
'driver' => 'mysql',
'host' => 'domain.com',
'port' => '3306',
'database' => 'mybd',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'options' => ['mode' => 'ssl'],
'strict' => false,
'engine' => null,
]
控制器
public function test()
{
$users = DB::connection('mysql2')->select("SELECT * FROM users");
dd($users);
}
解决方案:
- 尝试从
'options'=>['mode'=>'ssl']
中删除 SSL
。
- 暂时禁用远程数据库上的防火墙(如果您有访问权限)只是为了测试。如果有效,则在您的远程服务器上允许或添加源 http://localhost。
- 使用 VM 或 docker,在其中之一上配置 SSL。
SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (SQL: SELECT * FROM users)
我想在我的本地项目中连接到我的远程数据库,但是当我这样做时出现上面列出的错误。它在我的另一个数据库(来自本地主机)中工作,我如何连接我的远程服务器数据库?
database.php
'mysql2' => [
'driver' => 'mysql',
'host' => 'domain.com',
'port' => '3306',
'database' => 'mybd',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'options' => ['mode' => 'ssl'],
'strict' => false,
'engine' => null,
]
控制器
public function test()
{
$users = DB::connection('mysql2')->select("SELECT * FROM users");
dd($users);
}
解决方案:
- 尝试从
'options'=>['mode'=>'ssl']
中删除SSL
。 - 暂时禁用远程数据库上的防火墙(如果您有访问权限)只是为了测试。如果有效,则在您的远程服务器上允许或添加源 http://localhost。
- 使用 VM 或 docker,在其中之一上配置 SSL。