最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node JS error "getaddrinfo ENOTFOUND" - Stack Overflow

programmeradmin0浏览0评论

I'm having trouble in accessing MYSQL.

There is a GET METHOD at my code below :

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

When that method is executed, there is an error :

 unfortunately fail , error : Error: getaddrinfo ENOTFOUND
error stack: Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as onplete] (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)

And this is about the variables (express, mysql ...)

var http = require('http');
var express = require('express');
var request = require('request');
var mysql = require('mysql');

var client = mysql.createConnection({
    host:'',
    port : 3306,
    user : 'user',
    password : 'password',
    database  : 'database'
});
var app = express();
app.use(express.bodyParser());
app.use(app.router);

I'm having trouble in accessing MYSQL.

There is a GET METHOD at my code below :

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

When that method is executed, there is an error :

 unfortunately fail , error : Error: getaddrinfo ENOTFOUND
error stack: Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as onplete] (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)

And this is about the variables (express, mysql ...)

var http = require('http');
var express = require('express');
var request = require('request');
var mysql = require('mysql');

var client = mysql.createConnection({
    host:'http://nodejs.somewhere./WebMysql',
    port : 3306,
    user : 'user',
    password : 'password',
    database  : 'database'
});
var app = express();
app.use(express.bodyParser());
app.use(app.router);
Share Improve this question edited Dec 18, 2016 at 21:32 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Dec 1, 2015 at 17:43 LKMLKM 2,45010 gold badges30 silver badges56 bronze badges 3
  • I think it's not about code issue... isn't it? – LKM Commented Dec 1, 2015 at 17:44
  • Should I check whether mysql is running? then how? – LKM Commented Dec 1, 2015 at 17:44
  • a psycho downgraded my question! – LKM Commented Dec 1, 2015 at 18:16
Add a ment  | 

1 Answer 1

Reset to default 1

Your host setting for your mysql database connection is incorrect (ENOTFOUND for getaddrinfo means DNS resolution failed). It needs to be just the hostname of the mysql server (e.g. nodejs.somewhere.).

发布评论

评论列表(0)

  1. 暂无评论