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. Enter the password for the 'root'@'%' user.
  7. Set the region for your instance.

    Place your instance in the same region as the resources that access it. In most cases, you don't need to specify a zone.

  8. Under Advanced options, update any other settings you need for your instance:

    Setting Notes
    Database version
    Database version MySQL 5.6 or 5.7 (default).
    Machine type and storage
    Machine type The machine type determines the number of CPUs and the amount of memory your instance has. Learn more.
    Storage type Determines whether your instance uses SSD or HDD storage. Learn more.
    Storage capacity The amount of storage provisioned for the instance. Learn more.
    Automatic storage increase Determines whether Cloud SQL automatically provides more storage for your instance when free space runs low. Learn more.
    Automatic storage increase limit Determines how large your instance storage can grow automatically. Learn more.
    Automatic backups and high availability
    High availability If you need your instance to be configured for high availability, you must select the Create failover replica checkbox. Learn more.
    Automatic backups The window of time when you would like backups to start. Learn more.
    Binary logging Binary logging enables replication and point-in-time recovery. Learn more.
    Authorize networks
    Authorized networks For IP connections, only connections from authorized networks can connect to your instance. Learn more.
    Add Cloud SQL flags
    Cloud SQL flags You can use Cloud SQL flags to control settings and parameters for your instance. Learn more.
    Set maintenance schedule
    Maintenance window Determines a one-hour window when Cloud SQL can perform disruptive maintenance on your instance. If you do not set the window, then disruptive maintenance can be done at any time. Learn more.
    Maintenance timing Your preferred timing for instance updates, relative to other instances in the same project. Learn more.

  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] --region=[REGION]
    

    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-2 in the London region:

    gcloud sql instances create instance1 --tier=db-n1-standard-2 --region=europe-west2
    
    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).

    You can add more parameters to determine other instance settings:

    Setting Parameter Notes
    Required parameters
    Database version --database-version MYSQL_5_6 or MYSQL_5_7 (default).
    Region --region See valid values.
    Machine type and storage
    Machine type --tier The machine type determines the number of CPUs and the amount of memory your instance has. See valid values. Learn more.
    Storage type --storage-type Determines whether your instance uses SSD or HDD storage. Learn more.
    Storage capacity --storage-size The amount of storage provisioned for the instance, in GB. Learn more.
    Automatic storage increase --storage-auto-increase Determines whether Cloud SQL automatically provides more storage for your instance when free space runs low. Learn more.
    Automatic storage increase limit --storage-auto-increase-limit Determines how large Cloud SQL can automaticaly grow storage. Available only for the beta command (gcloud beta sql instances create). Learn more.
    Automatic backups and high availability
    High availability --failover-replica-name This parameter causes a failover replica to be created for the new instance. Learn more.
    Automatic backups --backup-start-time The window of time when you would like backups to start. Learn more.
    Binary logging --enable-bin-log Binary logging enables replication and point-in-time recovery. Learn more.
    Authorize networks
    Authorized networks --authorized-networks For IP connections, only connections from authorized networks can connect to your instance. Learn more.
    Add Cloud SQL flags
    Cloud SQL flags --database-flags You can use Cloud SQL flags to control settings and parameters for your instance. Learn more about Cloud SQL flags. Learn more about how to format this parameter.
    Set maintenance schedule
    Maintenance window --maintenance-window-day,
    --maintenance-window-hour
    Determines a one-hour window when Cloud SQL can perform disruptive maintenance on your instance. If you do not set the window, then disruptive maintenance can be done at any time. Learn more.
    Maintenance timing --maintenance-release-channel Your preferred timing for instance updates, relative to other instances in the same project. Use preview for earlier updates, and production for later updates. Learn more.

  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. Select the Users tab.
  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