Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Connecting to Google Cloud SQL from Google Compute Engine

This page shows you how to use MySQL Client, installed on a Google Compute Engine (GCE), to Google Cloud SQL using the standard MySQL wire protocol. At a high level, this scenario involves:

  • Granting the GCE instance IP access to your Google Cloud SQL instance.
  • Installing the MySQL client on your GCE instance.
  • Connecting to your Google Cloud SQL instance.
  • Setting the TCP keepalive of the GCE instance.

In the steps below, we assume that:

  • You have created and configured a GCE instance. For more information, see Accessing Google Compute Engine .
  • You know the external (public) IP address of your GCE instance.

To use MySQL Client from a GCE instance:

  1. Grant the GCE instance access to your Google Cloud SQL instance.

    You will do this by authorizing the IP address of the GCE instance as a network that can connect to your Cloud SQL instance. For more information, see Configuring access control for non-App Engine applications .

  2. Connect to your GCE instance using the gcutil tool.
    gcutil --project=<project-id> ssh <instance-name>
    
  3. Install MySQL client if it is not already installed.

    The command below shows how to install the MySQL client.

    sudo apt-get update
    sudo apt-get install mysql-client
    
  4. Connect with the MySQL client.
    mysql --host=<instance-ip-address> --user=<user-name> --password
    Enter password:
    Welcome to the MySQL monitor.
    ...
    mysql>
    

    For an example of how to connect using SSL, see Connecting Using MySQL Client .

  5. Run a MySQL command.
    SHOW PROCESSLIST;
    
  6. If you expect that connections between your GCE instance and your Cloud SQL instance will include long-lived unused connections, then you should be aware that connections with a GCE instance time out after 10 minutes of inactivity. For more information, see Networking and Firewalls in the Google Compute Engine documentation.

    To keep long-lived unused connections alive, you can set the TCP keepalive . The following command sets the TCP keepalive to one minute.

    sudo bash -c 'echo 60 > /proc/sys/net/ipv4/tcp_keepalive_time'
    

If you do not plan to continue connecting from your GCE instance, consider performing any of the following cleanup steps.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.