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 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? For help troubleshooting the proxy, see Troubleshooting Cloud SQL Proxy connections. Or, 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 for MySQL with Python
Java Using Cloud SQL for MySQL with Java
Node.js Using Cloud SQL for MySQL with Node.js
Go Using Cloud SQL for MySQL with Go
Ruby Using Cloud SQL for MySQL with Ruby
PHP Using Cloud SQL for MySQL with PHP
.NET Using Cloud SQL for MySQL with .NET

Need help? For help troubleshooting the proxy, see Troubleshooting Cloud SQL Proxy connections. Or, 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 Access Control > Authorization.
    4. In the Authorized App Engine 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? For help troubleshooting the proxy, see Troubleshooting Cloud SQL Proxy connections. Or, 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