Quickstart

This page shows you how to create and connect to a Google Cloud SQL instance and perform basic SQL operations using the Google Cloud Platform Console and the MySQL client.

Before you begin

  1. Sign in to your Google account.

    If you don't already have one, sign up for a new account.

  2. Select or create a Cloud Platform Console project.

    Go to the Projects page

  3. Enable billing for your project.

    Enable billing

  4. Enable the Cloud SQL Administration API.

    Enable the API

    You do not need to get credentials after enabling the API.

Create a Cloud SQL instance

  1. Go to the Google Cloud Platform Console.

    Go to the Google Cloud Platform Console

  2. Select your project and click Continue.

  3. Click Create Instance.
  4. Click Choose First Generation.
  5. Enter myinstance for Instance ID.

    Screenshot of the top part of the instance create screen

    Use the default values for the other fields.

  6. Click Create.

    You are returned to the instances list; your new instance is greyed out while it initializes and starts.

  7. When your new instance is available, click it to open the Instance details page.

  8. Click Access Control, then Users.

    Screenshot of the user creation page

  9. Click Create user account.

    Screenshot of the user creation dialog

  10. Enter root for User name.

  11. Enter a strong password that you can remember for Password.
  12. Leave Allow any host (%) selected.
  13. Click Create.
  14. Click IP address.

    Screenshot of the IP address addition page

  15. Click Request IPv4 address.

Connect to your instance using the MySQL client in the Cloud Shell

  1. In the Google Cloud Platform Console, click the Cloud Shell icon (Cloud Shell
icon) in the upper right corner.

    When the Cloud Shell finishes initializing, you should see:

    Welcome to Cloud Shell! For help, visit https://cloud.google.com/cloud-shell/help.
    username@example-id:~$
    

  2. At the Cloud Shell prompt, use the built-in MySQL client to connect to your Cloud SQL instance:

    gcloud beta sql connect myinstance --user=root
    
  3. Enter your root password.

    You should see:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 53
    Server version: 5.6.25-google-log (Google)
    Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    mysql>
    

Create a database and upload data

  1. Create a SQL database on your Cloud SQL instance:

    CREATE DATABASE guestbook;
    
  2. Insert sample data into the guestbook database:

    USE guestbook;
    CREATE TABLE entries (guestName VARCHAR(255), content VARCHAR(255),
        entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID));
        INSERT INTO entries (guestName, content) values ("first guest", "I got here!");
        INSERT INTO entries (guestName, content) values ("second guest", "Me too!");
    
  3. Retrieve the data from the database:

    SELECT * FROM entries;
    

    You should see:

    +--------------+-------------------+---------+
    | guestName    | content           | entryID |
    +--------------+-------------------+---------+
    | first guest  | I got here!       |       1 |
    | second guest | Me too!           |       2 |
    +--------------+-------------------+---------+
    2 rows in set (0.00 sec)
    mysql>
    

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
    Go to the Cloud SQL Instances page
  2. Select the myinstance instance to show the instance details.
  3. Click Delete.
  4. In the Delete instance window, type myinstance, then click Delete to delete the instance.

    Screenshot of the delete dialog

    You cannot reuse an instance name for approximately 7 days after an instance is deleted.

What's next

Send feedback about...