节点JS错误" getaddrinfo ENOTFOUND"

时间:2015-12-01 17:43:34

标签: javascript mysql node.js phpmyadmin node-mysql

我在访问MYSQL时遇到了麻烦。

我的代码中有一个GET METHOD:

app.get

执行该方法时,出现错误:

    app.get('/users',function(request,response){
    client.query('select * from User where 1=1',function(error,result){
        if(error){
            response.json('unfortunately fail');
            console.log('unfortunately fail , error : %s',error);
            console.log('error stack: %s',error.stack);
            console.log('error message: %s',error.message);
            throw error;
        }else{
            console.log('select success....');
            response.json('select success....');
            response.json(result);
        }
    });
});

这是关于变量(express,mysql ...)

 unfortunately fail , error : Error: getaddrinfo ENOTFOUND
error stack: Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
at Protocol._enqueue (/node_modules/mysql/lib/protocol/Protocol.js:135:48)
at Protocol.handshake (/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at Connection.connect (/node_modules/mysql/lib/Connection.js:123:18)
at Connection._implyConnect (/node_modules/mysql/lib/Connection.js:417:10)
at Connection.query (/node_modules/mysql/lib/Connection.js:199:8)
at app.listen.host (/web.js:70:10)
at callbacks (/node_modules/express/lib/router/index.js:164:37)
at param (/node_modules/express/lib/router/index.js:138:11)
at pass (/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/node_modules/express/lib/router/index.js:173:5)

1 个答案:

答案 0 :(得分:0)

您的mysql数据库连接的host设置不正确(getaddrinfo为ENOTFOUND表示DNS解析失败)。它只需要是mysql服务器的主机名(例如nodejs.somewhere.com)。