title: SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time,
body: <p>I try to connect 2 database in my <code>Laravel 5.6</code> project, but i got error like this</p>
  
  <blockquote>
    <p>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 <code>mt_merchant</code>)</p>
  </blockquote>
  
  <p><strong>I tried following code:</strong></p>
  
  <p><code>.env</code></p>
  
  <p><strong>1st db connection (this is in my local server)</strong></p>
  
  <pre><code>DB_CONNECTION=mysql
  DB_HOST=127.0.0.1
  DB_PORT=3306
  DB_DATABASE=thedaldb
  DB_USERNAME=root
  DB_PASSWORD=
  </code></pre>
  
  <p><strong>2nd db connection (this is in live server IP 18.188.209.59)</strong></p>
  
  <pre><code>DB_CONNECTION_SECOND=mysql
  DB_HOST_SECOND= 18.188.209.59
  DB_PORT_SECOND=3306
  DB_DATABASE_SECOND=delivery_test_copied
  DB_USERNAME_SECOND=testuser
  DB_PASSWORD_SECOND=testuser@123
  </code></pre>
  
  <p><code>app/config/database.php</code></p>
  
  <pre><code>'connections' =&gt; [
      'onlineorder' =&gt; [
              'driver'    =&gt; env('DB_CONNECTION_SECOND'),
              'host'      =&gt; env('DB_HOST_SECOND'),
              'port'      =&gt; env('DB_PORT_SECOND'),
              'database'  =&gt; env('DB_DATABASE_SECOND'),
              'username'  =&gt; env('DB_USERNAME_SECOND'),
              'password'  =&gt; env('DB_PASSWORD_SECOND'),
          ],
  ]
  </code></pre>
  
  <p><code>app/Models/OnlineOrder/OnlineOrder.php</code></p>
  
  <pre><code>&lt;?php
  namespace App\Models\OnlineOrder;
  use Illuminate\Database\Eloquent\Model;
  
  class OnlineOrder extends Model
  {
      protected $connection = 'onlineorder';
  
  }
  </code></pre>
  
  <p><code>app/Http/Controllers/Onlineorder/AppOnlineOrderController.php</code></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\Onlineorder;
  
  use Symfony\Component\HttpKernel\Exception\HttpException;
  use App\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Input;
  use App\Models\OnlineOrder\OnlineOrder;
  use Illuminate\Http\Response;
  use Illuminate\Http\Request;
  use Carbon\Carbon;
  use Validator;
  use Config;
  use File;
  use DB;
  
  
  class AppOnlineOrderController extends Controller
  {
      public function test($merchant_id)
      {
          $db_ext = DB::connection('onlineorder');
          $merchant = $db_ext-&gt;table('mt_merchant')-&gt;get(); //mt_merchant is table name
          print_r($db_ext);exit;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Simply i want to connect live server database in my local sever project</p>
  </blockquote>