title: error when connecting to db: { Error: connect ENOENT /var/run/mysqld/mysqld.sock
body: <p>I'm new on connecting MySQL on node js and I'm having an error.</p>
  
  <p>Here is my whole code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var express = require('express');
  var http = require('http');
  var path = require('path');
  var jquery = require('jquery');
  var app = express();
  var connection  = require('express-myconnection'); 
  var mysql = require('mysql');
  
  app.set('port', process.env.PORT || 6900);
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  app.use(express.logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded());
  app.use(express.methodOverride());
  
  app.use(express.static(path.join(__dirname, 'public')));
  
  // development only
  if ('development' == app.get('env')) {
    app.use(express.errorHandler());
  }
  
  app.use(
      
      connection(mysql,{
          
          host: '10.10.124.98',
          user: 'root',
          password : 'NLPZJNWF',
          port : 6900, //port mysql
          database:'areas',
    socketPath: '/var/run/mysqld/mysqld.sock'
  
      }) //or single
  
  );
  app.get('/', function(req, res){
  
    req.getConnection(function(err,connection){
         
          var query = connection.query('SELECT * FROM areas2015',function(err,rows)
          {
              if(err) {
                  console.log("Error Selecting : %s ",err );
     }
     else console.log("success");         
           });
    
      });
    
  });
  app.use(app.router);
  
  http.createServer(app).listen(app.get('port'), function(){
    console.log('Express server listening on port ' + app.get('port'));
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>And I'm having this error:</p>
  
  <pre><code>error when connecting to db: { Error: connect ENOENT /var/run/mysqld/mysqld.sock
      at Object.exports._errnoException (util.js:1018:11)
      at exports._exceptionWithHostPort (util.js:1041:20)
      at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
      --------------------
      at Protocol._enqueue (F:\New folder\Proj try\node_modules\mysql\lib\protocol\Protocol.js:110:48)
      at Protocol.handshake (F:\New folder\Proj try\node_modules\mysql\lib\protocol\Protocol.js:42:41)
      at Connection.connect (F:\New folder\Proj try\node_modules\mysql\lib\Connection.js:99:18)
      at Timeout.handleDisconnect [as _onTimeout] (F:\New folder\Proj try\node_modules\express-myconnection\lib\express-myconnection.js:12:17)
      at ontimeout (timers.js:386:14)
      at tryOnTimeout (timers.js:250:5)
      at Timer.listOnTimeout (timers.js:214:5)
    code: 'ENOENT',
    errno: 'ENOENT',
    syscall: 'connect',
    address: '/var/run/mysqld/mysqld.sock',
    fatal: true }
  </code></pre>
  
  <p>How do I fix this?</p>