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
Create a Cloud SQL instance
Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
Select your project and click Continue.
- Click Create Instance.
- Click Choose Second Generation.
myinstancefor Instance ID.
Use the default values for the other fields.
At the bottom of the page, click Create.
You are returned to the instances list; your new instance is greyed out while it initializes and starts.
When your new instance is available, click it to open the Instance details page.
- Click Access Control, then Users.
Click Change root password.
Enter a strong password that you can remember.
- Click OK.
Connect to your instance using the MySQL client in the Cloud Shell
In the Google Cloud Platform Console, click the Cloud Shell icon () in the upper right corner.
When the Cloud Shell finishes initializing, you should see:
Welcome to Cloud Shell! Type "help" to get started. username@example-id:~$
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
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
Create a SQL database on your Cloud SQL instance:
CREATE DATABASE guestbook;
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!");
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>
To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:
- Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
Go to the Cloud SQL Instances page
- Select the
myinstanceinstance to open the Instance details page.
- In the icon bar at the top of the page, click Delete.
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.
- Learn more about creating Cloud SQL instances.
- Learn about connecting to a Cloud SQL instance:
- Learn about creating MySQL users and databases for your Cloud SQL instance.