简体   繁体   English

连接节点v5.10.1时握手不活动超时错误。 到aws mysql RDS

[英]Handshake inactivity timeout error when connecting node v5.10.1. to aws mysql RDS

Im having a really hard to time solving this issue. 我很难及时解决这个问题。 When I try to connect node to aws's rds mysql database, I receive this error: 当我尝试将节点连接到aws的rds mysql数据库时,我收到此错误:

{ [Error: Handshake inactivity timeout]
  code: 'PROTOCOL_SEQUENCE_TIMEOUT',
  fatal: true,
  timeout: 10000 }

Solutions online suggest updating to node v4.2.1 but I am on v5.10.1. 解决方案在线建议更新到节点v4.2.1,但我在v5.10.1。 I have no problems when I connect node to my localhost mysql. 当我将节点连接到我的localhost mysql时,我没有任何问题。

Here is my code: 这是我的代码:

connectionpool = mysql.createPool({
        host     : 'dev-db.xxxxxx.us-west-2.rds.amazonaws.com',
        user     : 'xxxxx',
        password : 'xxxxx',
        database : 'decurate',

    });

app.get('/:table', function(req,res){
connectionpool.getConnection(function(err, connection) {
        if (err) {
            console.error('CONNECTION error: ',err);
            res.statusCode = 503;
              res.send({
                result: 'error',
                err:    err.code
            });
        } else {

           connection.query('SELECT * FROM user ORDER BY user_id DESC LIMIT 20', req.params.id, function(err, rows, fields) {
                if (err) {
                    console.error(err);
                    res.statusCode = 500;
                    res.send({
                        result: 'error',
                        err:    err.code
                    });
                }


                res.send({
                    result: 'success',
                    err:    '',
                    json:   rows
                });
                connection.release();
            });
        }
    });


});

Please advise. 请指教。

Thanks! 谢谢!

I guess the issue is with the host that cannot connect to mysql db. 我想问题是主机无法连接到mysql数据库。 I solved this by adding host configuration to my hosts file. 我通过将主机配置添加到我的hosts文件来解决这个问题。 Even if any aws instance you running, you should configure your domain name to hosts file. 即使您运行任何aws实例,也应将域名配置为hosts文件。 So that in your application configuration automatically lookup to desired IP Address. 这样在您的应用程序配置中自动查找所需的IP地址。

127.0.0.1     localhost
127.0.0.1     yourdomain.com

Restart your apache. 重启你的apache。

It works for me. 这个对我有用。 Try this & let me know. 试试这个并告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM