Quickstart for Cloud SQL for MySQL

This page shows you how to create and connect to a Cloud SQL MySQL 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 GCP project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud Platform project. Learn how to enable billing.

Create a Cloud SQL instance

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

    Go to the Cloud SQL Instances page

  2. Select your project and click Continue.

  3. Click Create Instance.

  4. Click MySQL.

  5. Enter myinstance for Instance ID.

    Screenshot of the instance creation screen

  6. Enter a password for the root user.

    Use the default values for the other fields.

  7. Click Create.

    You are returned to the instances list; you can click into the new instance right away to see the details, but it won't be available until it initializes and starts.

Connect to your instance using the mysql client in Cloud Shell

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

    When Cloud Shell finishes initializing, you should see:

    Welcome to Cloud Shell! Type "help" to get started.

  2. At the Cloud Shell prompt, connect to your Cloud SQL instance:

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

    You should see the mysql prompt.

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),
        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:
    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)

Clean up

To avoid incurring charges to your GCP 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 open the Instance details page.
  3. In the icon bar at the top of the page, click Delete.
  4. In the Delete instance window, type myinstance, then click Delete to delete the instance.

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

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud SQL for MySQL