node-mysql pool experiences ETIMEDOUT

前端 未结 1 1652
无人及你
无人及你 2021-01-28 09:04

I have a node-mysql pool configuration of

var db_init={
            host     : \'ip_address_of_GCS_SQL\',
            user     : \'user_name_of_GCS_SQL\',
               


        
相关标签:
1条回答
  • 2021-01-28 09:43

    I suspect the reason is that keepalive is not enabled on the connection to the MySQL server.

    node-mysql does not have an option to enable keepalive and neither does node-mysql2, but node-mysql2 provides a way to supply a custom function for creating sockets which we can use to enable keepalive:

    var mysql = require('mysql2');
    var net = require('net');
    
    var pool  = mysql.createPool({
      connectionLimit : 100,
      host            : '123.123.123.123',
      user            : 'foo',
      password        : 'bar',
      database        : 'baz',
      stream          : function(opts) {
        var socket = net.connect(opts.config.port, opts.config.host);
        socket.setKeepAlive(true);
        return socket;
      }
    });
    
    0 讨论(0)
提交回复
热议问题