NodeJS + MySQL从本地主机连接,但不是heroku

我有一个简单的networking应用程序需要连接到我的数据库。 我创build了一个名为public的用户,只能从数据库中select。

从本地主机一切正常工作。 我在Heroku上部署了应用程序,它给了我以下错误:

2016-10-18T00:17:59.282323 + 00:00 app [web.1]:无法连接:(错误:连接ETIMEDOUT 2016-10-18T00:17:59.282562 + 00:00 app [web.1]:出错了…错误:连接ETIMEDOUT

app.get("/", function(request, response){ response.render("index"); }); // request for quotes is received app.get("/get", function(req, res){ // open a connection to the database var connection = mysql.createConnection({ connectionLimit: 100, host: "my-test-database.c3j6vph7cyv2.us-west-2.rds.amazonaws.com", user: "public", password:"helloworld", database:"quotes" }); // connect to the database connection.connect(function(error){ if(error){ console.log("Couldn't connect :( " + error); } else { console.log("Connected successfully~!"); } }); // retrieve quotes from database connection.query("SELECT * FROM Quotes", function(error, rows, fields){ if (error) { console.log("Something went wrong... " + error); res.end(); } else { res.jsonp({"quotes": rows}); } }); connection.end(); }); 

看来你需要授权你的Heroku dynos来访问RDS(从你的代码中的URL我假设你正在使用它)。 检查这个链接的步骤