Skip to main content

Creating a Database and Table with Cloud SQL

Hands-On Lab

 

Photo of Broadus Palmer

Broadus Palmer

Google Cloud Training Architect

Length

00:30:00

Difficulty

Intermediate

Selecting the right type of instance to handle your data is a very important step. Just as important is creating the database and table to structure that data. In this hands-on lab, we will learn how to create a Cloud SQL database instance, create a database within that instance, and create a database table to structure the data.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating a Database and Table with Cloud SQL

Introduction

Selecting the right type of instance to handle your data is a very important step. Just as important is creating the database and table to structure that data. In this hands-on lab, we will learn how to create a Cloud SQL database instance, create a database within that instance, and create a database table to structure the data.

How to Log in to Google Lab Accounts

On the lab page, right-click Open GCP Console and select the option to open it in a new private browser window (this option will read differently depending on your browser — e.g., in Chrome, it says "Open Link in Incognito Window"). Then, sign in to Google Cloud Platform using the credentials provided on the lab page.

On the Welcome to your new account screen, review the text, and click Accept. In the "Welcome L.A.!" pop-up once you're signed in, check to agree to the terms of service, choose your country of residence, and click Agree and Continue.

Create a MySQL Cloud SQL Instance

  1. From the main console navigation, head over to SQL.
  2. Click Create instance.
  3. Choose MySQL.
  4. Set the following values:
    • Instance ID: game-instance
    • Root password: 12345
    • Zone: us-central-1a
  5. Click Create. It can take up to 15 minutes for it to finish being created.

Connect to the Instance Using the Google Cloud Shell

  1. Click on your newly created instance.

  2. In the Connect to this instance section, click Connect using Cloud Shell.

  3. Once connected, you will be prompted with a gcloud command:

    gcloud sql connect game-instance  --user=root –quiet
  4. Press Enter to start the command.

  5. Enter your password.

  6. You are now connected to the MySQL instance once you see the mysql> prompt.

Create a Database and Table Within the Cloud SQL Instance

  1. Check out any databases that were created within your instance:

    SHOW DATABASES;
  2. Create a new database:

    CREATE DATABASE gaming;
  3. Verify that the database was created:

    SHOW DATABASES;
  4. Use the gaming database to create a new table within it:

    USE gaming;
  5. Create a table and structure the data within the table:

    CREATE TABLE games (name VARCHAR(20), system VARCHAR(15), date DATE);
  6. Verify the table was created within the database:

    SHOW TABLES;

Conclusion

Congratulations on successfully completing this hands-on lab!