I am receiving an error which looks like this (in my functions log)
Access denied for user \'varun_admin\'@\'cloudsqlproxy~84.117.112.32\' (using password: YES)',
sqlMessage:
`\'varun_admin\'@\'cloudsqlproxy~84.117.112.32\' (using password: YES)',`
sqlState: '28000',
fatal: true }
(84.117.112.32
) intentionally modified.
I have double checked my username
and password
, In fact, I made a request from workbench and it went fine.
This is how I am creating/initialising my sql
const mysql = require('mysql')
const config = require('./../../config.js')
const connectionName = config.DB_CONNECTION_NAME
console.log(`Connection name: ${config.DB_CONNECTION_NAME}`)
const configSQL = {
host: config.DB_HOST,
user: config.DB_USER,
password: config.DB_PASSWORD,
database: config.DB_DATABASE
}
// Connection to cloud sql in production
if (!process.env.dev) {
configSQL.socketPath = `/cloudsql/${connectionName}`;
}
//SQL Config
const pool = mysql.createPool(configSQL)
// Checking if it was connected sucessfully or not on server startup
pool.getConnection((err, connection) => {
if (err) {
console.error('error connecting: ' + err)
return
}
console.log('connected as id ' + connection.threadId)
connection.release()
return
})
And the following function would typically make a call to get data
const getEverythingFromTable = tableName => {
return new Promise((resolve, reject) => {
pool.getConnection((error, connection) => {
if (error) return reject(error)
const query = `SELECT * FROM ${tableName}`
connection.query(query, (err, response) => {
connection.destroy()
if (err) return reject(err)
return resolve(response)
})
})
})
}
Any idea what I could be doing wrong?
SQL Logs
Update: 1
These are the environment values I am passing to the Cloud SQL Config
(Please refer to the code snippet above)
Where my cloudSQL config in the UI looks like this
How I am invoking functions/ calling them, the NodeJS code for it is above.