title: Error: connect ECONNREFUSED while accessing mysql
body: <p>I am new to node.js and trying to learn it.
  <br>
  I have installed node-mysql NPM module.
  Here i have listed my code to access mysql :</p>
  
  <pre><code>// Include http module, 
  var http = require('http'), 
  // And mysql module you've just installed. 
     mysql = require("mysql"); 
  
  // Create the connection. 
  // Data is default to new mysql installation and should be changed according to your configuration. 
  var connection = mysql.createConnection({ 
     user: "root", 
     password: "", 
     database: "astitvabmt",
     host: '127.0.0.1',
     port: '3306',
     _socket: '/var/run/mysqld/mysqld.sock'
  }); 
  
  // Create the http server. 
  http.createServer(function (req, res) {
     // Attach listener on end event. 
  
        // Query the database. 
        connection.query('SELECT * FROM tbluser;',function(err, results, fields) {
                  if (err) throw err;
                  console.log("sachin : " + results);
                  var output = '&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Latest Posts&lt;/h1&gt;&lt;ul&gt;&lt;table border=1&gt;&lt;tr&gt;';
                  for (var index in fields) {
                      output += '&lt;td&gt;' + fields[index].name + '&lt;/td&gt;';
                  }
                  output += '&lt;/tr&gt;';
                  for (var index in results) {
                      output += '&lt;tr&gt;&lt;td&gt;' + results[index].Recipe + '&lt;/td&gt;';
                      output += '&lt;td&gt;' + results[index].Amount + '&lt;/td&gt;';
                      output += '&lt;td&gt;' + results[index].Unit + '&lt;/td&gt;';
                      output += '&lt;td&gt;' + results[index].Ingredient + '&lt;/td&gt;&lt;/tr&gt;';
                  }
                  output += '&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;';
                  res.writeHead(200, {'Content-Type': 'text/html'});
                  res.end(output);
              });                       
  
  // Listen on the 8080 port. 
  }).listen(8080);
  console.log('Server mysqlJS running at 8080');
  </code></pre>
  
  <p>But i am getting error as :</p>
  
  <pre><code>sachin@ubuntu:/opt/lampp/htdocs/1nodeapp$ node mysql.js
  Server mysqlJS running at 8080
  
  Error: connect ECONNREFUSED
      at errnoException (net.js:901:11)
      at Object.afterConnect [as oncomplete] (net.js:892:19)
      --------------------
      at Handshake.Sequence (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
      at new Handshake (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
      at Protocol.handshake (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/protocol/Protocol.js:42:50)
      at Connection.connect (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/Connection.js:72:18)
      at Connection._implyConnect (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/Connection.js:182:10)
      at Connection.query (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/Connection.js:97:8)
      at Server.&lt;anonymous&gt; (/opt/lampp/htdocs/1nodeapp/mysql.js:22:18)
      at Server.EventEmitter.emit (events.js:98:17)
      at HTTPParser.parser.onIncoming (http.js:2108:12)
      at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
  </code></pre>
  
  <p>I don't have skip-networking option in my mysql config.
  <br>
  <strong>I have installed XAMPP in my PC.Previously i use 3306 port for mysql connection using apache.</strong></p>