从Heroku连接到AWS MySQL DB时发生ETIMEDOUT错误

所以我按照这里描述的所有步骤: https : //devcenter.heroku.com/articles/amazon_rds

当我运行heroku config命令,我得到:

 DATABASE_URL: mysql2://[username]:[password]@hostname... 

所以我在./config文件夹中添加了证书

当我尝试login时,连接超时,这是什么在日志中:

 2014-01-25T16:26:59.037529+00:00 app[web.1]: Express server listening on port 44600 2014-01-25T16:29:18.687464+00:00 heroku[api]: Add DATABASE_URL config by jason.mogera@outlook.com 2014-01-25T16:29:18.735263+00:00 heroku[api]: Release v11 created by jason.mogera@outlook.com 2014-01-25T16:29:18.882191+00:00 heroku[web.1]: State changed from up to starting 2014-01-25T16:29:21.439095+00:00 heroku[web.1]: Starting process with command `node app.js` 2014-01-25T16:29:22.778653+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2014-01-25T16:29:22.935805+00:00 app[web.1]: connect.multipart() will be removed in connect 3.0 2014-01-25T16:29:22.936445+00:00 app[web.1]: visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives 2014-01-25T16:29:22.936779+00:00 app[web.1]: connect.limit() will be removed in connect 3.0 2014-01-25T16:29:23.064077+00:00 app[web.1]: Express server listening on port 23430 2014-01-25T16:29:24.833326+00:00 heroku[web.1]: Process exited with status 143 2014-01-25T16:29:23.396737+00:00 heroku[web.1]: State changed from starting to up 2014-01-25T16:30:14.740476+00:00 app[web.1]: [90mPOST /login [32m200 [90m29992ms[0m 2014-01-25T16:30:14.736443+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path=/login host=www.novalist.co request_id=8ddc9973-03e4-4019-b47f-5da2efd84099 fwd="100.2.120.12" dyno=web.1 connect=3ms service=30001ms status=503 bytes=0 2014-01-25T16:30:59.002003+00:00 app[web.1]: [90mGET /login [32m200 [90m1016ms - 687b[0m 2014-01-25T16:30:59.007349+00:00 heroku[router]: at=info method=GET path=/login host=www.novalist.co request_id=bd43af72-53c6-4507-8e2c-ad3e318e36f4 fwd="100.2.120.12" dyno=web.1 connect=2ms service=1028ms status=200 bytes=687 2014-01-25T16:30:59.445343+00:00 app[web.1]: [90mGET /stylesheets/index-foundation.css [36m304 [90m9ms[0m 2014-01-25T16:30:59.457731+00:00 app[web.1]: [90mGET /stylesheets/style.css [32m200 [90m244ms - 1.07kb[0m 2014-01-25T16:30:59.466690+00:00 heroku[router]: at=info method=GET path=/stylesheets/style.css host=www.novalist.co request_id=c21b445c-941d-4cbb-ab68-a71fab00e24c fwd="100.2.120.12" dyno=web.1 connect=2ms service=254ms status=200 bytes=1098 2014-01-25T16:31:35.144892+00:00 app[web.1]: [90mPOST /login [32m200 [90m29998ms[0m 2014-01-25T16:31:52.078494+00:00 app[web.1]: at errnoException (net.js:901:11) 2014-01-25T16:31:52.078494+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:110:26) 2014-01-25T16:31:52.078494+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:42:41) 2014-01-25T16:31:52.078494+00:00 app[web.1]: at Connection.connect (/app/node_modules/mysql/lib/Connection.js:81:18) 2014-01-25T16:31:52.078494+00:00 app[web.1]: at Strategy.authenticate (/app/node_modules/passport-local/lib/passport-local/strategy.js:89:10) 2014-01-25T16:31:52.078494+00:00 app[web.1]: 2014-01-25T16:31:52.078720+00:00 app[web.1]: at pass (/app/node_modules/express/lib/router/index.js:145:5) 2014-01-25T16:31:52.078494+00:00 app[web.1]: at Strategy.module.exports [as _verify] (/app/auth.js:16:14) 2014-01-25T16:31:52.078494+00:00 app[web.1]: Error: connect ETIMEDOUT 2014-01-25T16:31:52.078720+00:00 app[web.1]: at Passport.authenticate (/app/node_modules/passport/lib/passport/middleware/authenticate.js:244:7) 2014-01-25T16:31:52.078494+00:00 app[web.1]: -------------------- 2014-01-25T16:31:52.078494+00:00 app[web.1]: at Object.afterConnect [as oncomplete] (net.js:892:19) 2014-01-25T16:31:52.078720+00:00 app[web.1]: at callbacks (/app/node_modules/express/lib/router/index.js:164:37) 2014-01-25T16:31:52.078720+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:138:11) 2014-01-25T16:31:52.078720+00:00 app[web.1]: at attempt (/app/node_modules/passport/lib/passport/middleware/authenticate.js:243:16) 2014-01-25T16:31:53.691098+00:00 heroku[web.1]: Process exited with status 8 2014-01-25T16:31:53.707160+00:00 heroku[web.1]: State changed from up to crashed 

您的rds端口/主机不能从heroky访问。 更改数据库安全组并允许heroku ip连接tcp / 3306

还要注意node-mysql 还不支持ssl连接。 如果您需要安全地连接到rds,则可能需要使用node-mysql2或node-mariasql