我正在连接到mysql数据库,一切都很好。突然,我开始收到TIMEOUT错误。所以,我尝试使用简单的测试代码进行连接。代码是:
var mysql = require('mysql');
var connection = mysql.createConnection({
host:'RDS HOST',
user:'user',
password:'password',
database:'database'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.end();
但是,我收到此错误:
Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (/sql-test/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)
--------------------
at Protocol._enqueue (/sql-test/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/sql-test/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/sql-test/node_modules/mysql/lib/Connection.js:130:18)
at Object.<anonymous> (/sql-test/sql-test.js:10:12)
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.runMain (module.js:604:10)
有些观点:
我的RDS数据库工作正常,没有安全组 阻止连接。我可以连接到我的RDS数据库抛出MySql Workbeanch或PHPMYADMIN没有问题。
代码是正确的。如果我更改在localhost上运行的mysql服务器的主机,我没有错误。
是否有人想知道出现此错误的其他原因?