我正在尝试连接到远程mysql(托管在digitalocean服务器上)并在本地计算机上使用db代码。
当我启动节点服务器并请求数据时,我收到以下错误。
{"ERRORMSG":"Something went wrong.{\"code\":\"ENOTFOUND\",\"errno\":\"ENOTFOUND\",\"syscall\":\"getaddrinfo\",\"hostname\":\"http://ip.of.remote.server/\",\"host\":\"http://ip.of.remote.server/\",\"port\":3306,\"fatal\":true}"}
第一次尝试后,如果我再次刷新,我会得到不同的错误
{\"code\":\"PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR\",\"fatal\":false}
连接是这样的:
connection = mysql.createConnection({
connectionLimit: 10000, //important
host: 'http://ip.of.remote.server/',
user: 'user',
password: 'password',
database: 'db',
multipleStatements: true,
connectionLimit : 100,
waitForConnections : true,
queueLimit :0,
debug : true,
wait_timeout : 28800,
connect_timeout :10
});
像这样打电话
app.get('/WSgetdata', function (req, res) {
var q = "CALL sp_get_data();"
var obj = {};
connection.connect();
connection.query(q, function (err, rows) {
if (err) {
obj.ERRORMSG = JSON.stringify(err);
}
else if((rows[rows.length-1])[0].ERRORSTATUS == 0){
//do something
}
res.end(JSON.stringify(obj))
});
});
出了什么问题。当代码和数据库在同一台机器上时,它工作正常。 此外,我还可以从所需的IP授予对db的访问权限。
TRACE
Trace
at Query._callback (d:/project/config\webservice.js:397:25)
at Query.Sequence.end (d:/project/node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
at d:/project/node_modules\mysql\lib\protocol\Protocol.js:390:18
at Array.forEach (native)
at d:/project/node_modules\mysql\lib\protocol\Protocol.js:389:13
at doNTCallback0 (node.js:407:9)
at process._tickCallback (node.js:336:13)
{ [Error: getaddrinfo ENOTFOUND http://ip.of.remote.server/ http://ip.of.remote.server/:3306]
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'http://ip.of.remote.server/',
host: 'http://ip.of.remote.server/',
port: 3306,
fatal: true }
Error: getaddrinfo ENOTFOUND http://ip.of.remote.server/ http://ip.of.remote.server/:3306
at errnoException (dns.js:25:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
--------------------
at Protocol._enqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:135:48)
at Protocol.handshake (d:/project/node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (d:/project/node_modules\mysql\lib\Connection.js:119:18)
at d:/project/config\webservice.js:387:20
at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
at next (d:/project/node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (d:/project/node_modules\express\lib\router\route.js:91:3)
at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
at d:/project/node_modules\express\lib\router\index.js:267:22
at Function.proto.process_params (d:/project/node_modules\express\lib\router\index.js:321:12)
Trace
at Query._callback (d:/project/config\webservice.js:397:25)
at Query.Sequence.end (d:/project/node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
at Protocol._validateEnqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:218:6)
at Protocol._enqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:129:13)
at Connection.query (d:/project/node_modules\mysql\lib\Connection.js:197:25)
at d:/project/config\webservice.js:388:20
at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
at next (d:/project/node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (d:/project/node_modules\express\lib\router\route.js:91:3)
at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }
Error: Cannot enqueue Query after fatal error.
at Protocol._validateEnqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:193:16)
at Protocol._enqueue (d:/project/node_modules\mysql\lib\protocol\Protocol.js:129:13)
at Connection.query (d:/project/node_modules\mysql\lib\Connection.js:197:25)
at d:/project/config\webservice.js:388:20
at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
at next (d:/project/node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (d:/project/node_modules\express\lib\router\route.js:91:3)
at Layer.handle [as handle_request] (d:/project/node_modules\express\lib\router\layer.js:82:5)
at d:/project/node_modules\express\lib\router\index.js:267:22
at Function.proto.process_params (d:/project/node_modules\express\lib\router\index.js:321:12)
答案 0 :(得分:0)
替换
host: 'http://ip.of.remote.server/',
与
host: 'ip.of.remote.server',