This page describes how to get started with Google Cloud SQL by:
- Creating a Google Cloud SQL instance
- Using the MySQL Client to connect a Google Cloud SQL instance
- Configuring a Google Cloud SQL instance
- Connecting to a Google Cloud SQL instance
You can also watch the video on this page which covers the same concepts. The video shows you how to create a Google Cloud SQL instance, configure it, and then connect to it from standard tools and from applications running on App Engine and Compute Engine.
Creating a Google Cloud SQL instance
Google Developers Console
- Go to the Google Developers Console .
- Create a new Developers Console project, or open an existing project by clicking on the project name.
- In the sidebar on the left, click STORAGE , and then click Cloud SQL to show a list of Cloud SQL instances for the project.
- Click New Instance to create a new Cloud SQL instance in your project.
-
Enter a name for the instance. The instance name will be automatically combined
with your project name, and any domain-specific names as shown here:
-
Non-domain:
your-project-name : your-instance-name
-
Domain-specific:
your-domain : your-project-name : your-instance-name
-
Non-domain:
- In the Assign IP Address section, select Assign IP Address .
- Also in the Assign IP Address section, in the Authorized IP Addresses box, add your IP address .
- Click Confirm to create the instance.
-
In the instance list, click the name of the instance you just created and note the
IP address
of the instance.
Use this as the IP address your applications or tools use to connect to the instance.
Cloud SQL Command Line
- Install the Cloud SDK if you haven't already.
-
Use the following command to create an instance:
$ gcloud sql instances create
your-instance-name
The instance name you specify will be automatically combined with your project name, and any domain-specific names as shown here:
-
Non-domain:
your-project-name : your-instance-name
-
Domain-specific:
your-domain : your-project-name : your-instance-name
-
Non-domain:
-
Modify the instance and grant access to
your IP address
:
$ gcloud sql instances patch your-instance-name --authorized-networks your-ip-address
-
Set the root password for the instance:
$ gcloud sql instances set-root-password your-instance-name --password-file path-to-file
-
Assign an IP address to the instance and retrieve it:
$ gcloud sql instances patch your-instance-name --assign-ip $ gcloud sql instances get your-instance-name
In the output, find the "ipAddress" field. Use this as the IP address your applications or tools use to connect to the instance.
That's it! You have created your Google Cloud SQL instance and you configured it with an IP address so you can connect to it. For instructions on migrating existing instances to use MySQL 5.6, see Migrating from MySQL 5.5 to MySQL 5.6 .
Using the MySQL Client to connect to a Google Cloud SQL instance
There are many ways you can connect to a Google Cloud SQL instance (see Configuring a Google Cloud SQL instance below). In the next steps, you will use the standard MySQL Client to create a database and query it.
- Install the MySQL Client .
-
Connect to the instance and use the IP address you created for it.
$ mysql --host=instance-IP --user=root --password
-
Create a database and table, enter some data, and query the data.
CREATE DATABASE guestbook; 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", "hello world!"); SELECT * FROM entries;
For more information about connecting using the MySQL Client, including how to connect with SSL, see Using MySQL Client .
Configuring a Google Cloud SQL instance
For information about managing your Google Cloud SQL instance, see:
- Configuring Access
- Setting a Root Password
- Creating, Editing, Deleting, and Restarting Instances
- Configuring SSL for an Instance
- Viewing Information about an Instance
- Importing and Exporting Data
- Schedule Backups and Configure Point-in-Time Recovery
Connecting to a Google Cloud SQL instance
You can connect to a Google Cloud SQL instance in the following ways:
- Using MySQL Client
- From Admin and Reporting tools
- From External Applications
- From Google Apps Script scripts
- From App Engine Java applications
- From App Engine Python applications
- From App Engine PHP applications
- From App Engine Go applications