Click here to Skip to main content
15,395,181 members
Articles / Hosted Services / Google Cloud
Article
Posted 26 Nov 2014

Tagged as

Stats

8.7K views
4 bookmarked

Getting Started with Google Cloud SQL

Rate me:
Please Sign up or sign in to vote.
4.33/5 (2 votes)
26 Nov 2014CC (Attr 3U)3 min read
This article describes how to get started with Google Cloud SQL

This article is a sponsored article. Articles such as these are intended to provide you with information on products and services that we consider useful and of value to developers

This page describes how to get started with Google Cloud SQL by:

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

  1. Go to the Google Developers Console.
  2. Create a new Developers Console project, or open an existing project by clicking on the project name.
  3. In the sidebar on the left, click Storage, and then click Cloud SQL to show a list of Cloud SQL instances for the project.
  4. Click New Instance to create a new Cloud SQL instance in your project.
  5. 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

    Note: You cannot re-use an instance name for up to two months after deleting that instance.

  6. Enter a name for the instance and click Save.
  7. After the instance is running, select the instance, and then click Access Control to finish configuring the instance.
    1. Click Request an IP Address and use this as the IP address your applications or tools use to connect to the instance.
    2. In the Set Root Password box, enter a root password, and click Set.
    3. Click Add Authorized Network and add your IP address.

Cloud SQL Command Line

  1. Install the Cloud SDK if you haven't already.
  2. 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

    Note: You cannot re-use an instance name for up to two months after deleting that instance.

  3. Modify the instance and grant access to your IP address:
    $ gcloud sql instances patch YOUR_INSTANCE_NAME --authorized-networks YOUR_IP_ADDRESS
  4. Set the root password for the instance:
    $ gcloud sql instances set-root-password YOUR_INSTANCE_NAME --password-file PASSWORD_FILE
  5. Assign an IP address to the instance and retrieve it:
    $ gcloud sql instances patch YOUR_INSTANCE_NAME --assign-ip
    $ gcloud sql instances describe 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.

  1. Install the MySQL Client.
  2. Connect to the instance and use the IP address you created for it.
    $ mysql --host=INSTANCE_IP --user=root --password
  3. 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:

Connecting to a Google Cloud SQL instance

You can connect to a Google Cloud SQL instance in the following ways:

Except as otherwise noted, the code samples of this page is licensed under the Apache 2.0 License.

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution 3.0 Unported License

Share

About the Author

Google Cloud Platform
United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --