-2

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

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
  • I'd suggest to google a little a check the docs which explains how to connect GAE to Cloud SQL https://cloud.google.com/sql/docs/mysql/connect-app-engine-standard. Also there are tons of similar questions for this https://stackoverflow.com/a/54330069/12265927. The SO community expect you have done some effort investigating the issue before creating a question and then show that investigation here and why you've not resolved the issue. – Puteri Aug 26 '21 at 23:25

1 Answers1

2

You need to use Unix sockets not the public IP of your Cloud SQL instance

For public IP paths, App Engine standard environment provides encryption and connects using the Cloud SQL Auth proxy through Unix sockets.

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

MBHA Phoenix
  • 2,029
  • 2
  • 11
  • 25