Lightsail instance node.js mysql connector timeout connecting to lightsail mysql database

0

I am running a node.js lightsail instance and have a script that connects to the database via node mysql2 connector, which works on my local machine on localhost when but when I run it in the lightsail instance the connection times out every time. I can connect to the mysql database using the cli in bitnami but when I use the same credentials to connect using node.js the connection times out. I tried at first with a mysql database inside the instance but that timed out so I made a lightsail database and attempted to connect to that and it too timed out.

my connection code is:

const user = process.env.USER
const pass = process.env.PASSWORD
const host = process.env.HOST

const con = mysql.createConnection({
    host: host,
    database: 'database_name',
    user: user,
    password: pass
})

the error that I am getting is:

text: 'Connection timeout: failed to create socket after 16006ms',
  sql: null,
  fatal: true,
  errno: 45012,
  sqlState: '08S01',
  code: 'ER_CONNECTION_TIMEOUT'
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南