连接到db时出错:{错误:连接ENOENT /var/run/mysqld/mysqld.sock

时间:2017-05-23 09:13:59

标签: mysql node.js

我是关于在节点j上连接MySQL的新手,我遇到了错误。

以下是我的全部代码:

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'));
});

我遇到了这个错误:

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 }

我该如何解决这个问题?

0 个答案:

没有答案