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'