title: Connecting remote mysql via local machine : node expressjs
body: <p>I am trying to connect to remote mysql(hosted on digitalocean server) and using the db for code in local machine.</p>
  
  <p>When I start the node server and request for data, I get the following error.</p>
  
  <pre><code>{"ERRORMSG":"Something went wrong.{\"code\":\"ENOTFOUND\",\"errno\":\"ENOTFOUND\",\"syscall\":\"getaddrinfo\",\"hostname\":\"http://ip.of.remote.server/\",\"host\":\"http://ip.of.remote.server/\",\"port\":3306,\"fatal\":true}"}
  </code></pre>
  
  <p>After the first attempt, if I refresh again I get different error</p>
  
  <pre><code>{\"code\":\"PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR\",\"fatal\":false}
  </code></pre>
  
  <p>Connection is made like this:</p>
  
  <pre><code>connection = mysql.createConnection({
      connectionLimit: 10000, //important
      host: 'http://ip.of.remote.server/',
      user: 'user',
      password: 'password',
      database: 'db',
      multipleStatements: true,
      connectionLimit : 100,
      waitForConnections : true,
      queueLimit :0,
      debug    :  true,
      wait_timeout : 28800,
      connect_timeout :10
  });
  </code></pre>
  
  <p>Call is made like this</p>
  
  <pre><code>app.get('/WSgetdata', function (req, res) {
      var q = "CALL sp_get_data();" 
      var obj = {};
      connection.connect();
      connection.query(q, function (err, rows) {
  
          if (err) {
              obj.ERRORMSG = JSON.stringify(err);
          }
          else if((rows[rows.length-1])[0].ERRORSTATUS == 0){
              //do something
          }
          res.end(JSON.stringify(obj))
      });
  });
  </code></pre>
  
  <p>What is wrong. It works fine when code and db are on same machine.
  Also I have grant access to db from desired IP.</p>
  
  <p>TRACE</p>
  
  <pre><code>  Trace
      at Query._callback (d:/project/config\webservice.js:397:25)
  at Query.Sequence.end (d:/project/node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
  at d:/project/node_modules\mysql\lib\protocol\Protocol.js:390:18
  at Array.forEach (native)
  at d:/project/node_modules\mysql\lib\protocol\Protocol.js:389:13
  at doNTCallback0 (node.js:407:9)
  at process._tickCallback (node.js:336:13)
  { [Error: getaddrinfo ENOTFOUND http://ip.of.remote.server/ http://ip.of.remote.server/:3306]
   code: 'ENOTFOUND',
   errno: 'ENOTFOUND',
   syscall: 'getaddrinfo',
   hostname: 'http://ip.of.remote.server/',
   host: 'http://ip.of.remote.server/',
   port: 3306,
   fatal: true }
   Error: getaddrinfo ENOTFOUND http://ip.of.remote.server/ http://ip.of.remote.server/:3306
  at errnoException (dns.js:25:10)
  at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
  --------------------
  at Protocol._enqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:135:48)
  at Protocol.handshake (d:/project/node_modules\mysql\lib\protocol\Protocol.js:52:41)
  at Connection.connect (d:/project/node_modules\mysql\lib\Connection.js:119:18)
  at d:/project/config\webservice.js:387:20
  at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
  at next (d:/project/node_modules\express\lib\router\route.js:110:13)
  at Route.dispatch (d:/project/node_modules\express\lib\router\route.js:91:3)
  at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
  at d:/project/node_modules\express\lib\router\index.js:267:22
  at Function.proto.process_params (d:/project/node_modules\express\lib\router\index.js:321:12)
  Trace
    at Query._callback (d:/project/config\webservice.js:397:25)
  at Query.Sequence.end (d:/project/node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
  at Protocol._validateEnqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:218:6)
  at Protocol._enqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:129:13)
  at Connection.query (d:/project/node_modules\mysql\lib\Connection.js:197:25)
  at d:/project/config\webservice.js:388:20
  at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
  at next (d:/project/node_modules\express\lib\router\route.js:110:13)
  at Route.dispatch (d:/project/node_modules\express\lib\router\route.js:91:3)
  at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
  { [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }
  Error: Cannot enqueue Query after fatal error.
  at Protocol._validateEnqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:193:16)
  at Protocol._enqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:129:13)
  at Connection.query (d:/project/node_modules\mysql\lib\Connection.js:197:25)
  at d:/project/config\webservice.js:388:20
  at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
  at next (d:/project/node_modules\express\lib\router\route.js:110:13)
  at Route.dispatch (d:/project/node_modules\express\lib\router\route.js:91:3)
  at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
  at d:/project/node_modules\express\lib\router\index.js:267:22
  at Function.proto.process_params (d:/project/node_modules\express\lib\router\index.js:321:12)
  </code></pre>