1
votes

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)

I want to connect to my remote database in my local project but when I do I get the error listed above. It works in my another database (from localhost), how can I connect my remote server database?

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,
]

Controller

public function test()
{
    $users = DB::connection('mysql2')->select("SELECT * FROM users");
    dd($users);
}
1
What are you using for local development? Xampp or vm or docker - Abdulla
Does the remote database allow you to connect with SQL Workbench? My guess is that you have some kind of remote block enabled. If you are using Cpanel you can log in and check under Remote MySQL if you are hosting it yourself you can check out This StackOverflow question - Suit Boy Apps
does the dbms server on your remote, listen public network or only localhost. It seems like yours is not open to public network (or lan if you're working on one) - Cemal
@abdulla_malik i am using xampp - Uzzal Hosen
@SuitBoyApps i have added host access - Uzzal Hosen

1 Answers

2
votes

Solutions:

  1. Try removing SSL from 'options'=>['mode'=>'ssl'].
  2. Disable firewall on the remote database(if you have the access) temporarily just to test. If it works then allow or add source http://localhost on your remote server.
  3. Use VM or docker, configure SSL on one of these.