node.js Server MySQL database connection timeout (error: connect etimeout)

Node. js server mysql database connection timeout problem
Sometimes connection timeouts occur while the Node server is connecting to the database. This Error is Error: Connect ETIMEDOUT. The error position in the code is line 421 to 433 of mysql’s Connection.js file:

Connection.prototype._handleConnectTimeout = function() {
  if (this._socket) {
    this._socket.setTimeout(0);
    this._socket.destroy();
  }

  var err = new Error('connect ETIMEDOUT');
  err.errorno = 'ETIMEDOUT';
  err.code = 'ETIMEDOUT';
  err.syscall = 'connect';

  this._handleNetworkError(err);
};

This error is literally a connection timeout, and then my error is due to the database connection problem, when creating the database should carefully compare the parameters of the problem, like me:
when creating the database connection pool:

pool = mysql.createPool({  
        host: "127.0.0.1",
        user: "user",
        password: "",
        database: "nodejs",
        port: 3306,
    });

The header information in the database is:

Source Server         : localhost
Source Server Version : 50624
Source Host           : localhost:3306
Source Database       : nodejs

Target Server Type    : MYSQL
Target Server Version : 50624
File Encoding         : 65001

It can be seen that there is a problem with the connection address of the server, so the connection was successful after changing to localhost

Read More: