DanielAttard
DanielAttard

Reputation: 3605

Cloud SQL / MySQL server fails after deploying to Google Cloud

I have a Google App Engine application that operates perfectly when run locally using localhost:8080, but after I deploy to the cloud using gcloud app deploy, I receive the following error:

Warning: PDO::__construct(): MySQL server has gone away in /base/data/home/apps/s~fileabcd/20190320t221240.123456737151234567/gac_abcd.php on line 7

Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in /base/data/home/apps/s~fileabcd/20190320t221240.123456737151234567/gac_abcd.php on line 7

Any ideas why this is happening?

Upvotes: 0

Views: 142

Answers (1)

DanielAttard
DanielAttard

Reputation: 3605

I discovered the reason why my Google App Engine (GAE) application functioned properly on localhost, but threw a MySQL server has gone away error after being deployed to [PROJECT-ID].appspot.com.

The reason is because my application was connecting to a Cloud SQL instance in a different project, and in order to do this you must grant the default appengine service account ([PROJECT-ID]@appspot.gserviceaccount.com) one of the following IAM roles:

  • Cloud SQL Client
  • Cloud SQL Editor
  • Cloud SQL Admin

After I added the App Engine default service account as a Cloud SQL Client Role in the project containing the Cloud SQL instance, everything worked perfectly.

From the Cloud SQL documentation.

Upvotes: 1

Related Questions