Search code examples
mysqlgoogle-app-enginegoogle-cloud-platformsequelize.jsgoogle-cloud-sql

Error Connecting GCP CloudSql using Sequilize through nodejs in app engine?


When I try to connect second generation Cloud mysql with app engine using sequilize it give me following Error:

{"name":"SequelizeConnectionError","parent":{"errno":"ENOENT","code":"ENOENT","syscall":"connect","address":"/cloudsql/phrasal-charger-215107:asia-south1:newdish123","fatal":true},"original":{"errno":"ENOENT","code":"ENOENT","syscall":"connect","address":"/cloudsql/phrasal-charger-215107:asia-south1:newdish123","fatal":true}}

Sequelize option set:-

const db = new Sequelize(
  config.database.db,
  config.database.username,
  config.database.password,
  {
    host:'localhost',
    dialect: "mysql",
    port: 3306,
    dialectOptions: {
        socketPath: '/cloudsql/phrasal-charger-215107:asia-south1:newdish123'
    }
  }
);

app.yaml

runtime: nodejs
env: flex


beta_settings:
  cloud_sql_instances: phrasal-charger-215107:asia-south1:newdish123

MORE INFO

I tried putting '/cloudsql/phrasal-charger-215107:asia-south1:newdish123' in host didn't work.

when I put public ip address in the host given by CloudSQL and setting my ip with GCP as authorised ip then the sequelize is running perfectly and performing operation as expected.


Solution

  • I was getting the exact same issue, all of my code base didn't change at all. What I did to fix it was to create a new project and then create new App Engine Instance and a new Cloud SQL database in my new project.

    Then I enabled SQL Admin for the project, created a new profile by running

    gcloud init
    

    and creating a new profile for the new project.

    Then I deployed the app again:

    gcloud app deploy
    

    You can find the setup of my project here:

    Node.JS on Google App Enging with Cloud SQLError: connect ENOENT /cloudsql/