Creating Instances

This page describes how to create a Google Cloud SQL for MySQL instance (either First Generation or Second Generation).

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. Select MySQL and click Next.
  4. Click Choose Second Generation.
  5. 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).
  6. 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.
  7. Enter the password for the 'root'@'%' user.
  8. If needed, set any of the other optional instance settings.
    For information about the optional settings, see Instance Settings.
  9. Click Create.

gcloud (2nd Gen)

For information about installing and getting started with the gcloud command-line tool, 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 sql instances create [INSTANCE_NAME] --tier=[MACHINE_TYPE]
    

    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 sql instances create instance1 --tier=db-n1-standard-8
    
    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. Note the automatically assigned IP address.

    If you are not using the Cloud SQL Proxy, you will use this address as the host address that your applications or tools use to connect to the instance.

  4. Set the password for the "root@%" MySQL user:
    gcloud sql users set-password root % --instance [INSTANCE_NAME] --password [PASSWORD]
    

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]",
                  "backupConfiguration": {"binaryLogEnabled":true, "enabled":true}}}' \
         -X POST \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances
    

    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. When the instance finishes initializing, update the root password:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"name": "root", "host": "%", "password": "[ROOT_PASSWORD]"}' \
         -X PUT \
         'https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/users?host=%25&name=root'
    
  3. Retrieve the automatically assigned IPv4 address for the new instance:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X GET \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]
    
    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. Select MySQL and click Next.
  4. Click Choose First Generation.
  5. 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).
  6. Choose a tier for the instance.
    For information about tiers, their capabilities, and their effect on pricing, see the Pricing page.
  7. If needed, set any of the optional instance settings.
    For information about the optional settings, see Instance Settings.
  8. Click Create.
  9. After the instance finishes initializing, select the instance to open it.
  10. Click Access Control > Users.
  11. 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 gcloud command-line tool, 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 users set-password root % --instance [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}}}' \
         -X POST \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances
    

    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]"}' \
         -X PUT \
         'https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/users?host=%25&name=root'
    
  3. Retrieve the automatically assigned IPv6 address for the new instance:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X GET \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]
    
    Look for the ipv6Address field in the response.

What's next

Send feedback about...

Cloud SQL for MySQL