I have deployed node js application into Google App Engine which has deployed successfully. I have also created db on cloud SQL and imported my local db there. I am facing the error to connect my node application with Cloud Sql DB, On local it is successfully connected with Cloud DB( I have added my local public IP in Sql Connection public IP section).Most probably it is a handshaking issue between node.js and cloud sql.please help me on what approach I have to follow. I am sharing the code as well as the error which is mentioned below :
Code
const mysql = require('mysql');
const dbConnection = mysql.createConnection({
host: '34.131.200.46',
user: 'admin',
password: 'admin@123',
port: 3306,
database: 'arcade',
// socketPath:'/cloudsql/google.com:ethereal-honor-206415:us-central1:arcade'
});
dbConnection.connect(connect=>{
console.log('connecttion =>>>>', connect)
});
exports.dbConnection = dbConnection;
Thanks & Regards Shubham
You need to use Unix sockets not the public IP of your Cloud SQL instance
Ref : https://cloud.google.com/sql/docs/mysql/connect-app-engine-standard#public-ip-default_1
Also make sure your service account has the appropriate Cloud SQL role and permissions.
More details here : https://cloud.google.com/sql/docs/mysql/connect-app-engine-standard#public-ip-default