2
votes

So I've setup two different GAE app projects, in the primary app i've created two Cloud SQL instances. I've granted access to my other app on both SQL instances.

When I attempt a simple PDO connection from the app which does not contain the cloud sql instances (live on GAE) I receive this error: SQLSTATE[HY000] [2006] MySQL server has gone away

here is the PHP connection line as per the GAE docs:

$db = new pdo('mysql:unix_socket=/cloudsql/<app-id>:<sql-instance-name>;dbname=<db-name>', 'root', '');

Connecting via IP from my local GAE SDK instance works as expected.

Any suggestions would be great!

So far I've tried:

  1. increasing the max_allowed_packet size 32000

  2. increasing the long_query_time to 60

  3. increasing the wait_timeout to 60

3

3 Answers

4
votes

The google app engine documentation states:

"Google Cloud Platform project called <your-project-id> is connecting to a Cloud SQL instance named <your-instance-name>."

You're probably getting an error because for project id you are using the project Id for your appengine application, not your Cloud SQL project ID.

Try:

$db = new pdo('mysql:unix_socket=/cloudsql/<sql-project-id>:<sql-instance-name>;dbname=<db-name>', 'root', '');
2
votes

In the Cloud Console's Instance Details, under Properties toward the bottom of the screen, there's a field called Instance connection name. So what worked for me was:

$db = new pdo('mysql:unix_socket=/cloudsql/<instance-connection-name>;dbname=<db-name>', 'root', '');
0
votes

This happened to me today, the problem for me was the app-id, make sure it includes the whole Google Apps domain. e.g. if your app is testapp, your instance is instancetest and your domain is domain.com the complete statement is:

$db = new pdo('mysql:unix_socket=/cloudsql/domain.com:testapp:instancetest;dbname=testdb', 'root', '');

Hope it helps.