title: Connection refused - Laravel, remote database
body: <p>In my local environment inserting data into my database works. However on my remote server it does not work.</p>
  
  <p>I have changed my remote .env and database.php files so that my remote database and server should work. I am able to connect to the database via <code>mysqlworkbench</code>, without any problems.</p>
  
  <p>However I am getting the following error:</p>
  
  <blockquote>
    <p>exception: "Illuminate\Database\QueryException"
    file: "/var/www/html/go/releases/1/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
        line: 664
        message: "SQLSTATE[HY000] [2002] Connection refused (SQL: insert into <code>temp_users</code> (<code>energy</code>, <code>diet</code>, <code>car</code>, <code>shortFlights</code>, <code>longFlights</code>, <code>email</code>, <code>country</code>, <code>total</code>, <code>updated_at</code>, <code>created_at</code>) values (1.13, 1.7, 0.55, 0, 0, test51@mail.com, Netherlands, 5.38, 2019-09-10 15:27:41, 2019-09-10 15:27:41))"
        trace: [,…]</p>
  </blockquote>
  
  <p>.env (replaced some values with defaults, to protect privacy).</p>
  
  <pre><code>APP_NAME=thename
  APP_ENV=production
  APP_KEY=the key
  APP_DEBUG=true
  APP_LOG_LEVEL=error
  APP_URL=theurl
  
  LOG_CHANNEL=stack
  
  DB_CONNECTION=mysql
  DB_HOST=localhost
  DB_PORT=3306
  DB_DATABASE=thedatabasename
  DB_USERNAME=theusername
  DB_PASSWORD=thepassword
  
  BROADCAST_DRIVER=log
  CACHE_DRIVER=file
  QUEUE_CONNECTION=sync
  SESSION_DRIVER=file
  SESSION_LIFETIME=120
  
  REDIS_HOST=localhost
  REDIS_PASSWORD=null
  REDIS_PORT=6379
  
  MAIL_DRIVER=smtp
  MAIL_HOST=smtp.mailtrap.io
  MAIL_PORT=2525
  MAIL_USERNAME=null
  MAIL_PASSWORD=null
  MAIL_ENCRYPTION=null
  
  PUSHER_APP_ID=
  PUSHER_APP_KEY=
  PUSHER_APP_SECRET=
  PUSHER_APP_CLUSTER=mt1
  
  MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
  MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
  </code></pre>
  
  <p>database.php (important section)</p>
  
  <pre><code>'mysql' =&gt; [
          'driver' =&gt; 'mysql',
          'host' =&gt; env('DB_HOST', 'localhost'),
          'port' =&gt; env('DB_PORT', '3306'),
          'database' =&gt; env('DB_DATABASE', 'thedatabasename'),
          'username' =&gt; env('DB_USERNAME', 'theusername'),
          'password' =&gt; env('DB_PASSWORD', 'thepassword'),
          'unix_socket' =&gt; env('DB_SOCKET', ''),
          'charset' =&gt; 'utf8mb4',
          'collation' =&gt; 'utf8mb4_unicode_ci',
          'prefix' =&gt; '',
          'prefix_indexes' =&gt; true,
          'strict' =&gt; true,
          'engine' =&gt; null,
      ],
  </code></pre>
  
  <p>The database name is correct. The table exists, and all the fields do too. Thanks in advance.</p>