0

I have a mysql db (which runs on gcps mysql instance). When I run the following code, I can connect to my database, however, when i deploy my code I cannot

Here is the code for reference - I am assuming it is some configuration issue. For reference my users are allowed to connect from any ip

exports.verify_mysql_credentials = async (data) => {
    const { host, user, password, database } = data;
    try {
      return new Promise((resolve, reject) => {
        const connection = mysql.createConnection({
          host,
          user,
          password,
          database,
        });
        connection.connect((error) => {
          if (error) {
            console.log("**********")
            console.log(error)
            reject(new Error('con failed'));
          } else {
            resolve();
          }
        });
        connection.end();
      });
      
    } catch (error) {
      throw error;
    }
  };

The exact error I am getting is

ETIMEDOUT
 at Connection._handleConnectTimeout (/workspace/node_modules/mysql/lib/Connection.js:409:13)
    at Object.onceWrapper (node:events:627:28)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:552:15)
    at Socket._onTimeout (node:net:550:8)
    at listOnTimeout (node:internal/timers:559:17)

Finally, I need this connect to work for general mysql databases not just google cloud so I would prefer a general solution not one that uses IAM or some different means of connection!

colinwink
  • 11
  • 1
  • 3
  • Have a look at this stackoverflow [link1](https://stackoverflow.com/questions/40868653/etimedout-error-when-querying-mysql-database) & [link2](https://stackoverflow.com/questions/60933582/error-connect-etimedout-at-connection-handleconnecttimeout-and-wierd-undefin) – Sathi Aiswarya Mar 04 '23 at 07:43

0 Answers0