在nodejs app中连接ETIMEDOUT错误

时间:2017-12-02 17:43:31

标签: javascript mysql node.js amazon-rds

我有以下代码,当我尝试运行我的应用时,它会给我一个连接eTIMEDOUT错误。我的信息在下面正确填写(之前有数据库连接,但查询后语法的更改导致了这个问题)。

var connection = mysql.createConnection({
  host     : "xx",
  user     : "xx",
  password : "xxx",
  port     : "3306",
});

connection.connect();
connection.query('SELECT id FROM neighborhoods', function(err, rows, fields) {
    if(err) console.log(err);
    console.log('The solution is: ', rows);

});
connection.end();

我的终端然后显示:

{ Error: connect ETIMEDOUT
    at Connection._handleConnectTimeout (/Users/abaric/Documents/Repos/philly-guide/node_modules/mysql/lib/Connection.js:419:13)
    at Socket.g (events.js:292:16)
    at emitNone (events.js:86:13)
    at Socket.emit (events.js:185:7)
    at Socket._onTimeout (net.js:338:8)
    at ontimeout (timers.js:386:11)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)
    --------------------
    (omitted stuff)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
  errorno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  fatal: true }
The solution is:  undefined

有什么想法?我查看了与https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/

这样相同语法的教程

0 个答案:

没有答案