简体   繁体   English

节点 JS 错误“getaddrinfo ENOTFOUND”

[英]Node JS error "getaddrinfo ENOTFOUND"

I'm having trouble in accessing MYSQL.我在访问 MYSQL 时遇到问题。

There is a GET METHOD at my code below :下面的代码中有一个 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);
        }
    });
});

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

And this is about the variables (express, mysql ...)这是关于变量(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.com/WebMysql',
    port : 3306,
    user : 'user',
    password : 'password',
    database  : 'database'
});
var app = express();
app.use(express.bodyParser());
app.use(app.router);

Your host setting for your mysql database connection is incorrect ( ENOTFOUND for getaddrinfo means DNS resolution failed).您的 mysql 数据库连接的host设置不正确( getaddrinfo 的ENOTFOUND表示 DNS 解析失败)。 It needs to be just the hostname of the mysql server (eg nodejs.somewhere.com ).它只需要是 mysql 服务器的主机名(例如nodejs.somewhere.com )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM