Creating Instances

This page describes how to create a Google Cloud SQL instance (either First Generation or Second Generation). A Google Cloud SQL instance is a MySQL database hosted in Google's cloud.

For detailed information about all instance settings, see Instance Settings.

Creating a Second Generation instance

To create a Second Generation instance:

Console (2nd Gen)

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Click Create instance.
  3. Click Choose Second Generation.
  4. Enter an ID for the instance.
    You do not need to prepend the project ID onto the instance ID. This is done automatically where appropriate (for example, in the log files).
  5. If you want to configure the instance for high availability, select the Create failover replica check box.
    For more information about the high availability configuration, see Overview of the High Availability Configuration.
  6. If needed, set any of the other optional instance settings.
    For information about the optional settings, see Instance Settings.
  7. Click Create.
  8. After the instance finishes initializing, select the instance to open it.
  9. Click Access Control > Users.
  10. Click Change root password and provide a password for the 'root'@'%' MySQL user.

gcloud (2nd Gen)

For information about installing and getting started with the Cloud SDK, see Installing Cloud SDK. For information about the Cloud Shell, see Google Cloud Shell.

  1. Show the list of potential machine types:
    gcloud sql tiers list
    

    Note the values that begin with db-. You must choose one of these values to create a Second Generation instance.

    For information about the different machine types, their capabilities, and their effect on instance pricing, see the Pricing page.

  2. Create the instance:
    gcloud beta sql instances create [INSTANCE_NAME] --tier=[MACHINE_TYPE] --activation-policy=ALWAYS
    

    Where MACHINE_TYPE is one of the values from the previous step that starts with db-.

    For example, the following command creates a Second Generation instance called instance1 with the machine type of db-n1-standard-8:

    gcloud beta sql instances create instance1 --tier=db-n1-standard-8 --activation-policy=ALWAYS
    
    You do not need to prepend the project ID onto the instance ID. This is done automatically where appropriate (for example, in the log files).

    For information about other available parameters, see the gcloud beta sql instances create command reference and Instance Settings.

  3. Set the password for the "root@%" MySQL user:
    gcloud sql instances set-root-password [INSTANCE_NAME] --password [PASSWORD]
    
  4. Retrieve the automatically assigned IPv4 address:
    gcloud beta sql instances describe [INSTANCE_NAME]
    

    In the output, find the ipAddress field. You can use this as the IP address your applications or tools use to connect to the instance.

cURL (2nd Gen)

  1. Create the instance:
    ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name":"[INSTANCE_NAME]", "region":"[REGION]",
                  "settings": {"tier":"[MACHINE_TYPE]", "activationPolicy":"ALWAYS",
                  "backupConfiguration": {"binaryLogEnabled":true, "enabled":true}}}' \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances \
         -X POST
    

    This example creates an instance with backups and binary logging enabled. These settings are optional. For a complete list of parameters for this call, see the Instances:insert page. For information about instance settings, including valid values for region and machine type, see Instance Settings.

  2. Update the root password:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name": "root", "host": "%", "password": "[ROOT_PASSWORD]"}' \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/users?host=%25&name=root \
         -X PUT
    
  3. Retrieve the automatically assigned IPv4 address for the new instance:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME] \
         -X GET
    
    Look for the ipAddress field in the response.

Creating a First Generation instance

To create a First Generation instance:

Console (1st Gen)

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Click Create instance.
  3. Click Choose First Generation.
  4. Enter a name for the instance.
    You do not need to prepend the project ID onto the instance ID. This is done automatically where appropriate (for example, in the log files).
  5. Choose a tier for the instance.
    For information about tiers, their capabilities, and their effect on pricing, see the Pricing page.
  6. If needed, set any of the optional instance settings.
    For information about the optional settings, see Instance Settings.
  7. Click Create.
  8. After the instance finishes initializing, select the instance to open it.
  9. Click Access Control > Users.
  10. Click Create user account and create a user with name root and specify a password.

    This creates the MySQL user 'root'@'%'. For more information about MySQL users, see MySQL Users.

gcloud (1st Gen)

For information about installing and getting started with the Cloud SDK, see Installing Cloud SDK. For information about the Cloud Shell, see Google Cloud Shell.

  1. Show the list of potential machine types:
    gcloud sql tiers list
    

    Note the values that begin with capital D. You must choose one of these values to create a First Generation instance. Choosing one of the other values, such as db-n1-standard-1, results in creating a Second Generation instance.

    For information about the different tiers, their capabilities, and their effect on instance pricing, see the see the Pricing page.

  2. Create the instance:

    gcloud sql instances create [INSTANCE_NAME] --tier=[TIER]
    

    Where TIER is one of the values from the gcloud sql tiers list command that starts with a capital D.

    For example, the following command creates a First Generation instance called instance1 with the machine type of D4:

    gcloud sql instances create instance1 --tier=D4
    
    You do not need to prepend the project ID onto the instance ID. This is done automatically where appropriate (for example, in the log files).

    For information about other available parameters, see the gcloud sql instances create command reference and Instance Settings.

  3. Activate the "root@%" user account for the instance:
    gcloud sql instances set-root-password [INSTANCE_NAME] --password [PASSWORD]
    

    You must activate this MySQL user account before you can connect to the instance using the MySQL protocol.

  4. Retrieve the automatically assigned IPv6 address:
    gcloud sql instances describe [INSTANCE_NAME]
    

    In the output, find the ipv6Address field. You can use this as the IP address your applications or tools use to connect to the instance. You can also request an IPv4 address, which incurs a small charge while the instance is not activated.

cURL (1st Gen)

  1. Create the instance:
    ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name":"[INSTANCE_NAME]", "region":"[REGION]",
                  "settings": {"tier":"[TIER]",
                  "backupConfiguration": {"binaryLogEnabled":true, "enabled":true}}}' \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances \
         -X POST
    

    This example creates an instance with backups and binary logging enabled, and an activation policy of ON_DEMAND.

    For a complete list of parameters for this call, see the Instances:insert page. For information about instance settings, including valid values for region and tier, see Instance Settings.

  2. After the instance finishes initializing, activate the root user account:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name": "root", "host": "%", "password": "[ROOT_PASSWORD]"}' \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/users?host=%25&name=root \
         -X PUT
    
  3. Retrieve the automatically assigned IPv6 address for the new instance:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME] \
         -X GET
    
    Look for the ipv6Address field in the response.

What's next

Send feedback about...

Cloud SQL Documentation