Connecting MySQL Client Using IP Addresses

This page describes how to connect MySQL Client, either running locally on your client machine or in the Cloud Shell, to your Google Cloud SQL instance over IP.

  1. Before you begin
  2. Using a local MySQL client
    1. Install the MySQL client
    2. Configure access to your Cloud SQL instance
    3. Connect to your Cloud SQL instance without encryption
    4. Connect to your Cloud SQL instance using SSL
  3. Using the MySQL client in the Cloud Shell
  4. What's next

Before you begin

Before you can start using MySQL Client you must have:

Using a local MySQL client

Using a local MySQL client to connect to your Cloud SQL instance involves three high-level tasks:

  1. Install the MySQL client
  2. Configure access to your Cloud SQL instance
  3. Connect to your Cloud SQL instance

Install the MySQL client

To install the MySQL client:

Debian

Install the MySQL client from the package manager:

sudo apt-get update
sudo apt-get install mysql-client

CentOS and RHEL

Install the MySQL client from the package manager:

sudo yum install mysql

openSUSE

Install the MySQL client from the package manager:

sudo zypper install mysql-client

Other platforms

  1. Download the MySQL Community Server for your platform from the MySQL Community Server download page.
    The Community Server includes the MySQL client.
  2. Install the Community Server, following the directions on the download page.

For more information about installing MySQL, see the MySQL Reference Manual Installing and Upgrading MySQL.

Configure access to your Cloud SQL instance

To configure access to your instance:

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

    Go to the Cloud SQL Instances page

  2. Record the IP address of the instance.

    Instance listing with IP address highlighted.

  3. Log in to the client machine where your MySQL client is installed.
  4. Click What's my IP to determine the IP address of the client machine.
  5. In the Instances page in the Google Cloud Platform Console, click the instance to open its Overview page.
  6. Click Access control > Authorization.
  7. Under Authorized networks, click Add network and enter the IP address of the client machine where your MySQL client is installed.

    Authorized networks and Add network button.

  8. Click Done, then click Save at the bottom of your page to save your changes.

    Save button for Authrorization page highlighted.

  9. Connect to your instance, either with SSL or without SSL.

Connect to your Cloud SQL instance without encryption

To connect to your instance:

  1. Start the MySQL client:
    mysql --host=[INSTANCE_IP] --user=root --password
    
  2. Enter the root password at the prompt.
  3. Verify your connection by listing the databases on the instance:
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    

    For information about troubleshooting connection issues over IP, see Diagnosing Issues with Cloud SQL Instances.

Connect to your Cloud SQL instance using SSL

To connect to your instance using SSL:

  1. If your instance is not configured for SSL, or you need a new client certificate, configure the instance for SSL and create a client certificate by following the instructions at Configuring SSL for Instances.
    You should have the following three items:
    • A Certificate Authority (CA) certificate, with its text in a file called server-ca.pem.
    • A server public key certificate, with its text in a file called client-cert.pem.
    • A client private key, with its text in a file called client-key.pem.
  2. Start the MySQL client:
    mysql --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem \
                 --host=[INSTANCE_IP] --user=root --password
    
  3. Enter the root password at the prompt.
  4. At the MySQL prompt, enter the \s command to verify that your connection is using SSL.
  5. Look for the output line with SSL:.
    ...
    SSL:                     Cipher in use is DHE-RSA-AES256-SHA
    ...
    
  6. Verify your connection by listing the databases on the instance:
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    

    For information about troubleshooting connection issues over IP, see Diagnosing Issues with Cloud SQL Instances.

Using the MySQL client in the Cloud Shell

  1. Go to the Google Cloud Platform Console.
    Go to the Google Cloud Platform Console
  2. Click the Cloud Shell icon towards the right in the tool bar.
    The Cloud Shell takes a few moments to initialize.
  3. At the Cloud Shell prompt, use the built-in MySQL client to connect to your Cloud SQL instance:
    gcloud beta sql connect [INSTANCE_ID] --user=root
    
  4. Enter your root password.
  5. Verify your connection by listing the databases on the instance:
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    

What's next

Send feedback about...