Create and query a Cloud SQL for MySQL database using the Google Cloud console

Learn how to create and query a Cloud SQL for MySQL database using the Google Cloud console. This quickstart is intended for database practitioners seeking a quick introduction to Cloud SQL for MySQL. The quickstart takes you through the steps required to complete the following tasks:

  • Create a Cloud SQL for MySQL instance
  • Create a database
  • Create a schema
  • Create a table
  • Insert data
  • Query the data that you inserted
  • Clean up your resources

As you follow along, keep the default values for settings unless otherwise specified.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Cloud SQL, Cloud SQL Admin, and Compute Engine APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Cloud SQL, Cloud SQL Admin, and Compute Engine APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

Required roles

To get the permissions that you need to complete this quickstart, ask your administrator to grant you the Cloud SQL Admin (roles/cloudsql.admin) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

Create a Cloud SQL for MySQL instance

Create an instance in the Google Cloud console using the following settings. For all other settings, keep the default.

  1. Go to the Cloud SQL Instances page in the Google Cloud console.
    Go to the Cloud SQL Instances page
  2. Click Create Instance.
  3. Click Choose Cloud SQL for MySQL.
  4. For Choose a Cloud SQL edition, choose Enterprise.
  5. For Edition preset, select Sandbox.
  6. For Instance ID, enter quickstart-instance.
  7. Enter a password for the default user account and save it for future use.
  8. Choose a region near you.
  9. For Zonal availability, select Single zone.
  10. Click Create instance, and then wait until the instance initializes and starts. The initialization process can take more than five minutes.

Create a database

After quickstart-instance has been created, you can create a database in your Cloud SQL for MySQL instance.