Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
节点和MySQL到数据库的连接_Mysql_Node.js - Fatal编程技术网

节点和MySQL到数据库的连接

节点和MySQL到数据库的连接,mysql,node.js,Mysql,Node.js,我需要为模块提供MySQL连接,所以我提供如下代码: var express = require('express'); var mysql = require('mysql') var app = express(); var connection = mysql.createConnection({ host: '149.xxx.xx.x', user: 'User', password: 'Password', database: 'DataBase',

我需要为模块提供MySQL连接,所以我提供如下代码:

var express = require('express');
var mysql = require('mysql')
var app = express();

var connection = mysql.createConnection({
    host: '149.xxx.xx.x',
    user: 'User',
    password: 'Password',
    database: 'DataBase',
    port: 1443, 
});

connection.connect(
    function(error) {
        console.log(error.code); // 'ECONNREFUSED'
        console.log(error.fatal); // true
        console.log(error.sql); 
        console.log(error.sqlMessage);     
}
);
过了一段时间(大约1-2分钟),我从控制台收到一个错误。日志:

ECONNRESET
true
undefined
undefined
我想这可能是因为我的“不活跃”而导致的超时,但当我尝试执行查询时,错误是相同的


你知道怎么了吗?我从DataGrip检查了它,数据是正确的。

好的,我在这里发现了一个小错误。数据库是MS SQL Server(microsoft)。我正在尝试使用名为
mssql
的库连接到该数据库,提供一些代码:

var config = {
    server: "149.xxx.xx.x",
    database: "Database",
    user: "User",
    password: "Password",
    connectionTimeout: 300000,
    requestTimeout: 300000,
    pool: {
        idleTimeoutMillis: 300000,
        max: 100
    }
};

function getEmp() {
    var connection = new sql.Connection(config);
    var req = new sql.Request(connection);

    connection.connect(function (error) {
        if(error) {
            console.log(error);
            return;
        }
        req.query('Procedure', function(err, data) {
            if (err) {
                console.log(err);
            } else {
                console.log(data);
            }
            connection.close();
        });
    });
}

getEmp();
我收到了错误信息:

{ ConnectionError: Failed to connect to 149.xxx.xx.x:1433 - connect ETIMEDOUT 149.xxx.xx.x:1433
at Connection.<anonymous> (/Users/phuzarski/Learning/NodeJS/srv-express/node_modules/mssql/lib/tedious.js:353:25)
at Connection.g (events.js:292:16)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Connection.socketError (/Users/phuzarski/Learning/NodeJS/srv-express/node_modules/tedious/lib/connection.js:791:12)
at Socket.<anonymous> (/Users/phuzarski/Learning/NodeJS/srv-express/node_modules/tedious/lib/connection.js:33:15)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1277:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)


 name: 'ConnectionError',
  message: 'Failed to connect to 149.xxx.xx.x:1433 - connect ETIMEDOUT 149.xxx.xx.x:1433',
  code: 'ESOCKET' }
{ConnectionError:未能连接到149.xxx.xx.x:1433-连接ETIMEDOUT 149.xxx.xx.x:1433
连接时。(/Users/phuzarski/Learning/NodeJS/srv express/node_modules/mssql/lib/tedious.js:353:25)
在Connection.g(events.js:292:16)
在emitOne(events.js:96:13)
在Connection.emit(events.js:188:7)
位于Connection.socketError(/Users/phuzarski/Learning/NodeJS/srv express/node_modules/tedious/lib/Connection.js:791:12)
在插座上。(/Users/phuzarski/Learning/NodeJS/srv express/node_modules/tedious/lib/connection.js:33:15)
在emitOne(events.js:96:13)
在Socket.emit(events.js:188:7)
在emitErrorNT(net.js:1277:8)
at _combinedTickCallback(内部/流程/下一步_tick.js:80:11)
名称:'ConnectionError',
消息:“未能连接到149.xxx.xx.x:1433-连接ETIMEDOUT 149.xxx.xx.x:1433”,
代码:'ESOCKET'}
确保数据正确-此处DataGrip连接良好


我在谷歌发现了类似的问题,问题是TCP/IP被禁用。我检查了这一个,并使用端口1443启用了它。

您是如何进行查询的?你能展示一下代码吗?你确定它是MySQL服务器吗?端口1443是MS SQL Server的默认端口。@mscdex我明天会问,但后端开发人员告诉了我mysql。当然,我会尽快检查节点库的mssql。@我检查了mscdex,它必须是MS SQL Server。我正在使用mssql库,但现在出现了如下错误:name:'ConnectionError',message:'Failed to xxx.xxx.xx.x:1433 in 15000ms',code:'ETIMEOUT'}我的错误,我相信它实际上是1433 for MS SQL Server。我相信这可能是一个输入错误,仍然是一个MS SQL Server实例(3306是默认的MySQL端口号)。