title: Why is node script failing a localhost connect to MySQL
body: <p>I can't figure out why a script to is failing to connect to the MySQL instance.</p>
  
  <p><strong>I can connect to the database from the mysql client on the command line, with the exact same credentials.
  I can connect to the database from a remote client, using the same credentials.</strong></p>
  
  <p>The database connect script works fine if I set the parameters to a remote database.</p>
  
  <p>Neither host or socket parameters works through the script.
  I make dumb mistakes at times but if this is another one, I can't see it.</p>
  
  <p>An outside observer would help me here.</p>
  
  <p>==================== DB Connect code</p>
  
  <pre><code>var db = require('./config');
  var mysql = require('mysql');
  
  var connection = mysql.createConnection({
      host: db.db_parms.host,
      port: db.db_parms.port,
      user: db.db_parms.user,
      password: db.db_parms.password,
      database: db.db_parms.context,
      debug:true
  });
  
  connection.connect(function(err) {
      if(err){
          console.log("SQL CONNECT ERROR: " + err);
      } else {
          console.log("SQL CONNECT SUCCESSFUL.");
      }
  });
  
  connection.query("SELECT now()", function(error,results,fields) {
      console.log("Results:" + results);
      console.log("Fields:" + fields);
  });
  
  
  exports.connection = connection;
  </code></pre>
  
  <p>=== Error Stack returned:</p>
  
  <pre><code>SQL CONNECT ERROR: Error: connect ECONNREFUSED 127.0.0.1:3307
      at Object.exports._errnoException (util.js:1036:11)
      at exports._exceptionWithHostPort (util.js:1059:20)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
      --------------------
      at Protocol._enqueue (/home/kingram/node/apps/fss_register/node_modules/mysql/lib/protocol/Protocol.js:141:48)
      at Protocol.handshake (/home/kingram/node/apps/fss_register/node_modules/mysql/lib/protocol/Protocol.js:52:41)
      at Connection.connect (/home/kingram/node/apps/fss_register/node_modules/mysql/lib/Connection.js:130:18)
      at Object.&lt;anonymous&gt; (/home/kingram/node/apps/fss_register/db/db_connect.js:19:12)
      at Module._compile (module.js:556:32)
      at Object.Module._extensions..js (module.js:565:10)
      at Module.load (module.js:473:32)
      at tryModuleLoad (module.js:432:12)
      at Function.Module._load (module.js:424:3)
      at Module.runMain (module.js:590:10)
  </code></pre>
  
  <p>========= config.js with host = 'localhost':</p>
  
  <pre><code>var db_parms = {
  host: 'localhost',
  port: 3307,
  user:'foo',
  password:'bar',
  database:'thisone'
  }
  
  exports.db_parms = db_parms;
  </code></pre>
  
  <p>========= config.js with host = socket:</p>
  
  <pre><code>host: '/var/run/mysqld/mysqld.sock',
  </code></pre>
  
  <p>=== Error Stack returned:</p>
  
  <pre><code>SQL CONNECT ERROR: Error: getaddrinfo ENOTFOUND /var/run/mysqld/mysqld.sock /var/run/mysqld/mysqld.sock:3307
      at errnoException (dns.js:28:10)
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
      --------------------
      at Protocol._enqueue (/home/kingram/node/apps/fss_register/node_modules/mysql/lib/protocol/Protocol.js:141:48)
      at Protocol.handshake (/home/kingram/node/apps/fss_register/node_modules/mysql/lib/protocol/Protocol.js:52:41)
      at Connection.connect (/home/kingram/node/apps/fss_register/node_modules/mysql/lib/Connection.js:130:18)
      at Object.&lt;anonymous&gt; (/home/kingram/node/apps/fss_register/db/db_connect.js:19:12)
      at Module._compile (module.js:556:32)
      at Object.Module._extensions..js (module.js:565:10)
      at Module.load (module.js:473:32)
      at tryModuleLoad (module.js:432:12)
      at Function.Module._load (module.js:424:3)
      at Module.runMain (module.js:590:10)
  </code></pre>
  
  <p>I'm not sure if the error from the socket is a permissions issue or not and if that is relevant.</p>