我尝试通过nodejs连接aws mysql
var mysql = require('mysql')
var connection = mysql.createConnection({
host : 'xxxx.xxxc.ap-northeast-1.rds.amazonaws.com',
port : '3306',
user : 'dbusername',
password : 'passwords',
database : 'dbname'
})
connection.connect(function(err){
if(!err) {
console.log("connected ... ")
} else {
console.log(err)
}
});
当我运行这段代码时,它会花费几秒钟,然后显示以下错误 -
{ Error: connect ETIMEDOUT
at Connection._handleTimeoutError (/node_modules/mysql2/lib/connection.js:181:13)
at ontimeout (timers.js:466:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:267:5)
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true }
我搜索了很多,找不到正确的答案,我尝试使用 node-mysql2
,有同样的问题。有什么想法吗?
最佳答案
通过任何 mysql 客户端(mysql workbench、dbninja 等)连接你的 mysql aws rds 来检查它,如果你能够通过任何客户端连接它,那么一定是 nodejs 设置有问题,否则它会与RDS 详细信息。
同时检查 RDS 是否限制了对特定 VPN 的访问,因此您的 Node 服务器应该在同一个 VPN 中才能连接。
关于mysql - 通过 node.js 连接 aws mysql 时总是显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51530531/