简体   繁体   中英

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:

{ [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. I have no problems when I connect node to my 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. I solved this by adding host configuration to my hosts file. Even if any aws instance you running, you should configure your domain name to hosts file. So that in your application configuration automatically lookup to desired IP Address.

127.0.0.1     localhost
127.0.0.1     yourdomain.com

Restart your apache.

It works for me. Try this & let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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