Connecting from App Engine

This page provides language-specific links to informaton about how to set up a connection from an App Engine application and a Cloud SQL Second Generation instance. It also describes how to set up a connection between an App Engine standard environment application and a First Generation instance.

For information about the various options for connecting to Cloud SQL, see Connection Options for External Applications.

App Engine standard environment to Second Generation

For information about connecting from App Engine standard environment to Second Generation instances, see the App Engine documentation for your programming language:
Language Documentation
Python Using Google Cloud SQL with Python
Java Using Google Cloud SQL with Java
PHP Using Google Cloud SQL with PHP
Go Using Google Cloud SQL with Go

Need help? See our Cloud SQL Support page.

App Engine flexible environment to Second Generation

For information about connecting from App Engine flexible environment to Second Generation instances, see the App Engine documentation for your programming language:
Language Documentation
Python Using Cloud SQL with Python
Java Using Cloud SQL with Java
Node.js Using Cloud SQL with Node.js
Go Using Cloud SQL with Go
Ruby Using Cloud SQL with Ruby
PHP Using Cloud SQL with PHP
.NET Using Cloud SQL with .NET

Need help? See our Cloud SQL Support page.

App Engine standard environment to First Generation

  1. Grant the application access:

    Console

    1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

      Go to the Cloud SQL Instances page

    2. Click the instance name to open its Overview page.
    3. Select the Authorization tab.
    4. In the Authorized App Engine Standard applications section, click Add application ID and enter the application ID.
    5. Click Done to exit edit mode.
    6. Click Save to update the instance.

    gcloud

    1. List the existing authorized App Engine applications for the instance.
      gcloud sql instances describe [INSTANCE_NAME]
      
    2. Use the sql instances patch command to provide the names for all applications that can access this instance. Use commas to separate multiple application names.
      gcloud sql instances patch [INSTANCE_NAME] --authorized-gae-apps [GAE_APP_NAME]
      
  2. Update your application:
    1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

      Go to the Cloud SQL Instances page

    2. Click the instance name to open its Overview page.
    3. Copy the Instance connection name from the Properties.
    4. Use the following connection string in your application:
      /cloudsql/<INSTANCE_CONNECTION_NAME>
      

      The complete code statement depends on your language and framework.

Need help? See our Cloud SQL Support page.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud SQL for MySQL