exploring cloud SQL databases whith gcloud CLI SDK


In [90]:
#some help
!gcloud sql --help


NAME
    gcloud sql - manage Cloud SQL databases

SYNOPSIS
    gcloud sql GROUP | COMMAND [GCLOUD_WIDE_FLAG ...]

DESCRIPTION
    Manage Cloud SQL databases.

GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --configuration,
    --flatten, --format, --help, --log-http, --project, --quiet, --trace-token,
    --user-output-enabled, --verbosity. Run $ gcloud help for details.

GROUPS
    GROUP is one of the following:

     backups
        Provide commands for working with backups of Cloud SQL instances.

     databases
        Provide commands for managing databases of Cloud SQL instances.

     flags
        Provide a command to list flags.

     instances
        Provide commands for managing Cloud SQL instances.

     operations
        Provide commands for working with Cloud SQL instance operations.

     ssl-certs
        Provide commands for managing SSL certificates of Cloud SQL instances.

     tiers
        Provide a command to list tiers.

     users
        Provide commands for managing Cloud SQL users.

COMMANDS
    COMMAND is one of the following:

     connect
        Connects to a Cloud SQL instance.

In [91]:
#some help on instances
!gcloud sql instances --help


NAME
    gcloud sql instances - provide commands for managing Cloud SQL instances

SYNOPSIS
    gcloud sql instances COMMAND [GCLOUD_WIDE_FLAG ...]

DESCRIPTION
    Provide commands for managing Cloud SQL instances including creating,
    configuring, restarting, and deleting instances.

GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --configuration,
    --flatten, --format, --help, --log-http, --project, --quiet, --trace-token,
    --user-output-enabled, --verbosity. Run $ gcloud help for details.

COMMANDS
    COMMAND is one of the following:

     clone
        Clones a Cloud SQL instance.

     create
        Creates a new Cloud SQL instance.

     delete
        Deletes a Cloud SQL instance.

     describe
        Displays configuration and metadata about a Cloud SQL instance.

     export
        Exports data from a Cloud SQL instance.

     failover
        Causes a high-availability Cloud SQL instance to failover.

     import
        Imports data into a Cloud SQL instance from Google Cloud Storage.

     list
        Lists Cloud SQL instances in a given project.

     patch
        Updates the settings of a Cloud SQL instance.

     promote-replica
        Promotes Cloud SQL read replica to a stand-alone instance.

     reset-ssl-config
        Deletes all client certificates and generates a new server certificate.

     restart
        Restarts a Cloud SQL instance.

     restore-backup
        Restores a backup of a Cloud SQL instance.

     set-root-password
        (DEPRECATED) Sets the password of the MySQL root user.

In [92]:
#list the existing instances
!gcloud sql instances list


Listed 0 items.

In [93]:
#we will create a new instance, let's get some help
!gcloud sql instances create --help


NAME
    gcloud sql instances create - creates a new Cloud SQL instance

SYNOPSIS
    gcloud sql instances create INSTANCE
        [--activation-policy=ACTIVATION_POLICY] [--assign-ip] [--async]
        [--authorized-gae-apps=APP,[APP,...]]
        [--authorized-networks=NETWORK,[NETWORK,...]] [--no-backup]
        [--backup-start-time=BACKUP_START_TIME] [--cpu=CPU]
        [--database-flags=FLAG=VALUE,[FLAG=VALUE,...]]
        [--database-version=DATABASE_VERSION; default="MYSQL_5_6"]
        [--enable-bin-log] [--failover-replica-name=FAILOVER_REPLICA_NAME]
        [--follow-gae-app=FOLLOW_GAE_APP] [--gce-zone=GCE_ZONE]
        [--maintenance-release-channel=MAINTENANCE_RELEASE_CHANNEL]
        [--maintenance-window-day=MAINTENANCE_WINDOW_DAY]
        [--maintenance-window-hour=MAINTENANCE_WINDOW_HOUR]
        [--master-instance-name=MASTER_INSTANCE_NAME] [--memory=MEMORY]
        [--pricing-plan=PRICING_PLAN, -p PRICING_PLAN; default="PER_USE"]
        [--region=REGION; default="us-central"] [--replica-type=REPLICA_TYPE]
        [--replication=REPLICATION] [--require-ssl] [--storage-auto-increase]
        [--storage-size=STORAGE_SIZE] [--storage-type=STORAGE_TYPE]
        [--tier=TIER, -t TIER] [GCLOUD_WIDE_FLAG ...]

DESCRIPTION
    Creates a new Cloud SQL instance.

POSITIONAL ARGUMENTS
     INSTANCE
        Cloud SQL instance ID.

FLAGS
     --activation-policy=ACTIVATION_POLICY
        The activation policy for this instance. This specifies when the
        instance should be activated and is applicable only when the instance
        state is RUNNABLE. More information on activation policies can be found
        here: https://cloud.google.com/sql/faq#activation_policy.
        ACTIVATION_POLICY must be one of: ALWAYS, NEVER, ON_DEMAND.

     --assign-ip
        Specified if the instance must be assigned an IP address.

     --async
        Display information about the operation in progress, without waiting
        for the operation to complete.

     --authorized-gae-apps=APP,[APP,...]
        First Generation instances only. List of IDs for App Engine
        applications running in the Standard environment that can access this
        instance.

     --authorized-networks=NETWORK,[NETWORK,...]
        The list of external networks that are allowed to connect to the
        instance. Specified in CIDR notation, also known as 'slash' notation
        (e.g. 192.168.100.0/24).

     --backup
        Enables daily backup. Enabled by default, use --no-backup to disable.

     --backup-start-time=BACKUP_START_TIME
        The start time of daily backups, specified in the 24 hour format -
        HH:MM, in the UTC timezone.

     --cpu=CPU
        A whole number value indicating how many cores are desired in the
        machine. Both --cpu and --memory must be specified if a custom machine
        type is desired, and the --tier flag must be omitted.

     --database-flags=FLAG=VALUE,[FLAG=VALUE,...]
        A comma-separated list of database flags to set on the instance. Use an
        equals sign to separate flag name and value. Flags without values, like
        skip_grant_tables, can be written out without a value after, e.g.,
        skip_grant_tables=. Use on/off for booleans. View the Instance Resource
        API for allowed flags. (e.g., --database-flags
        max_allowed_packet=55555,skip_grant_tables=,log_output=1)

     --database-version=DATABASE_VERSION; default="MYSQL_5_6"
        The database engine type and version. DATABASE_VERSION must be one of:
        MYSQL_5_5, MYSQL_5_6, MYSQL_5_7, POSTGRES_9_6.

     --enable-bin-log
        Specified if binary log should be enabled. If backup configuration is
        disabled, binary log must be disabled as well.

     --failover-replica-name=FAILOVER_REPLICA_NAME
        Also create a failover replica with the specified name.

     --follow-gae-app=FOLLOW_GAE_APP
        First Generation instances only. The App Engine app this instance
        should follow. It must be in the same region as the instance.

     --gce-zone=GCE_ZONE
        The preferred Compute Engine zone (e.g. us-central1-a, us-central1-b,
        etc.).

     --maintenance-release-channel=MAINTENANCE_RELEASE_CHANNEL
        Which channel's updates to apply during the maintenance window.
        MAINTENANCE_RELEASE_CHANNEL must be one of:

         preview
            Preview updates release prior to production updates. You may wish
            to use the preview channel for dev/test applications so that you
            can preview their compatibility with your application prior to the
            production release.
         production
            Production updates are stable and recommended for applications in
            production.

     --maintenance-window-day=MAINTENANCE_WINDOW_DAY
        Day of week for maintenance window, in UTC time zone.
        MAINTENANCE_WINDOW_DAY must be one of: SUN, MON, TUE, WED, THU, FRI,
        SAT.

     --maintenance-window-hour=MAINTENANCE_WINDOW_HOUR
        Hour of day for maintenance window, in UTC time zone.

     --master-instance-name=MASTER_INSTANCE_NAME
        Name of the instance which will act as master in the replication setup.
        The newly created instance will be a read replica of the specified
        master instance.

     --memory=MEMORY
        A whole number value indicating how much memory is desired in the
        machine. A size unit should be provided (eg. 3072MiB or 9GiB) - if no
        units are specified, GiB is assumed. Both --cpu and --memory must be
        specified if a custom machine type is desired, and the --tier flag must
        be omitted.

     --pricing-plan=PRICING_PLAN, -p PRICING_PLAN; default="PER_USE"
        First Generation instances only. The pricing plan for this instance.
        PRICING_PLAN must be one of: PER_USE, PACKAGE.

     --region=REGION; default="us-central"
        The regional location (e.g. asia-east1, us-east1). See the full list of
        regions at https://cloud.google.com/sql/docs/instance-locations.

     --replica-type=REPLICA_TYPE
        The type of replica to create. REPLICA_TYPE must be one of: READ,
        FAILOVER.

     --replication=REPLICATION
        The type of replication this instance uses. REPLICATION must be one of:
        SYNCHRONOUS, ASYNCHRONOUS.

     --require-ssl
        Specified if users connecting over IP must use SSL.

     --storage-auto-increase
        Storage size can be increased, but it cannot be decreased; storage
        increases are permanent for the life of the instance. With this setting
        enabled, a spike in storage requirements can result in permanently
        increased storage costs for your instance. However, if an instance runs
        out of available space, it can result in the instance going offline,
        dropping existing connections.

     --storage-size=STORAGE_SIZE
        Amount of storage allocated to the instance. Must be an integer number
        of GB between 10GB and 10230GB inclusive.

     --storage-type=STORAGE_TYPE
        The storage type for the instance. STORAGE_TYPE must be one of: SSD,
        HDD.

     --tier=TIER, -t TIER
        The tier for this instance. For Second Generation instances, TIER is
        the instance's machine type (e.g., db-n1-standard-1). For PostgreSQL
        instances, only shared-core machine types (e.g., db-f1-micro) apply. A
        complete list of tiers is available here:
        https://cloud.google.com/sql/pricing.

GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --configuration,
    --flatten, --format, --help, --log-http, --project, --quiet, --trace-token,
    --user-output-enabled, --verbosity. Run $ gcloud help for details.

In [94]:
#what are the tiers available?
!gcloud sql tiers list


TIER               AVAILABLE_REGIONS                                                                                                 RAM        DISK
D0                 us-central,europe-west1,us-east1,asia-east1                                                                       128 MiB    250 GiB
D1                 us-central,europe-west1,us-east1,asia-east1                                                                       512 MiB    250 GiB
D2                 us-central,europe-west1,us-east1,asia-east1                                                                       1 GiB      250 GiB
D4                 us-central,europe-west1,us-east1,asia-east1                                                                       2 GiB      250 GiB
D8                 us-central,europe-west1,us-east1,asia-east1                                                                       4 GiB      250 GiB
D16                us-central,europe-west1,us-east1,asia-east1                                                                       8 GiB      250 GiB
D32                us-central,europe-west1,us-east1,asia-east1                                                                       16 GiB     250 GiB
db-f1-micro        us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  614.4 MiB  3.0 TiB
db-g1-small        us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  1.7 GiB    3.0 TiB
db-n1-standard-1   us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  3.8 GiB    10.0 TiB
db-n1-standard-2   us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  7.5 GiB    10.0 TiB
db-n1-standard-4   us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  15 GiB     10.0 TiB
db-n1-standard-8   us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  30 GiB     10.0 TiB
db-n1-standard-16  us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  60 GiB     10.0 TiB
db-n1-standard-32  us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  120 GiB    10.0 TiB
db-n1-highmem-2    us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  13 GiB     10.0 TiB
db-n1-highmem-4    us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  26 GiB     10.0 TiB
db-n1-highmem-8    us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  52 GiB     10.0 TiB
db-n1-highmem-16   us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  104 GiB    10.0 TiB
db-n1-highmem-32   us-central1,europe-west1,europe-west2,us-east1,us-east4,asia-east1,asia-northeast1,australia-southeast1,us-west1  208 GiB    10.0 TiB

In [95]:
#we put our instance name here
instance_name="instance-toto"

In [96]:
# let's create our instance
!gcloud sql instances create {instance_name} \
        --region "europe-west2" \
        --tier=db-f1-micro \
        --storage-type=HDD


Creating Cloud SQL instance...done.                                            
Created [https://www.googleapis.com/sql/v1beta4/projects/future-sonar-168815/instances/instance-toto].
NAME           REGION        TIER         ADDRESS        STATUS
instance-toto  europe-west2  db-f1-micro  35.189.65.164  RUNNABLE

In [97]:
#let's check it's created
!gcloud sql instances list


NAME           REGION        TIER         ADDRESS        STATUS
instance-toto  europe-west2  db-f1-micro  35.189.65.164  RUNNABLE

In [98]:
#let's check it's created correctly
!gcloud sql instances describe {instance_name}


backendType: SECOND_GEN
connectionName: future-sonar-168815:europe-west2:instance-toto
databaseVersion: MYSQL_5_6
etag: '"7nzH-h2yIa30FGKFRs9YFu88s0g/MQ"'
instanceType: CLOUD_SQL_INSTANCE
ipAddresses:
- ipAddress: 35.189.65.164
  type: PRIMARY
kind: sql#instance
name: instance-toto
project: future-sonar-168815
region: europe-west2
selfLink: https://www.googleapis.com/sql/v1beta4/projects/future-sonar-168815/instances/instance-toto
serverCaCert:
  cert: |-
    -----BEGIN CERTIFICATE-----
    MIIDITCCAgmgAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMSMwIQYDVQQDExpHb29n
    bGUgQ2xvdWQgU1FMIFNlcnZlciBDQTEUMBIGA1UEChMLR29vZ2xlLCBJbmMxCzAJ
    BgNVBAYTAlVTMB4XDTE3MDcwMTExMzgwNFoXDTE5MDcwMTExMzkwNFowSDEjMCEG
    A1UEAxMaR29vZ2xlIENsb3VkIFNRTCBTZXJ2ZXIgQ0ExFDASBgNVBAoTC0dvb2ds
    ZSwgSW5jMQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
    ggEBAIq5a4FmYiZPwH1hDY1tWNskgFRGOrB7FvuM9vYYNcAZ/PJgyzJVt6vLE6mU
    XBAJb0aHNHrDoMcnS6QxkEPpbEAOFHMZ/+IjXDZ1wzn7nIxHy1RLfovmMldZbcyZ
    aSjuqscbKMdrR+nIFaYCBSraKwIYHib4MmSDc1olvq5LhT2WPML4yZuasjyxrptz
    Jud+n71mk49zrpZoGjkfRBKdzTPF+mPi3B5vUZjADKJG2mhaZQQ9Ba7VoeMH2y9X
    5sG1EjjZyLkZLkG3tpnAJ0G70ZgbgwCIas7D2jUF5pSOa3Xq/P2nC7OGZtzUcxtu
    pjgnOyA7H/BTLQwbiwweLvRF+EUCAwEAAaMWMBQwEgYDVR0TAQH/BAgwBgEB/wIB
    ADANBgkqhkiG9w0BAQUFAAOCAQEAGK/BgsQg18o/j23qWNivmRFyfUJ3d0BeTTcU
    posur77PVVRntJf/ShF/KeCnC0H55WyXZIBRFY3R88P6Mm3numTh/ae/2Hn+MpZu
    g4eS9OOVSqv4En7DPA2i3pafV3LKp4ziqPFEIYit1cz3REYeOCPnsAlVHv5Tm7gi
    DaYZ941gASJdH6jlzUxHNA1w0Rs1j6GjqiVx3ZQcz4FWvI6euj6gdaThOLbRw2yM
    fUTMwzQjYNIyRtWa77uTRg3qfj07SkylHMpnPNTnyvxVeMCbaRiS6dwGC8ADQq3/
    G/Bkzj5+IBZi1qrsELhB9UR74Q6OjJ6/Pm81ScMODYgJnC8ogg==
    -----END CERTIFICATE-----
  certSerialNumber: '0'
  commonName: C=US,O=Google\, Inc,CN=Google Cloud SQL Server CA
  createTime: '2017-07-01T11:38:04.140000+00:00'
  expirationTime: '2019-07-01T11:39:04.140000+00:00'
  instance: instance-toto
  kind: sql#sslCert
  sha1Fingerprint: 35f969a50f60a1c338d28839fda52c34b1609a17
serviceAccountEmailAddress: o5eq2jyvcnayhppcwl7ffohe4e@speckle-umbrella-6.iam.gserviceaccount.com
settings:
  activationPolicy: ALWAYS
  backupConfiguration:
    enabled: false
    kind: sql#backupConfiguration
    startTime: '23:00'
  dataDiskSizeGb: '10'
  dataDiskType: PD_HDD
  ipConfiguration:
    ipv4Enabled: true
  kind: sql#settings
  pricingPlan: PER_USE
  replicationType: SYNCHRONOUS
  settingsVersion: '1'
  storageAutoResize: true
  storageAutoResizeLimit: '0'
  tier: db-f1-micro
state: RUNNABLE

In [109]:
#we set a nice password
password='toto'
!gcloud sql users set-password root % \
    --instance {instance_name} \
    --password {password}


Updating Cloud SQL user...done.                                                

In [117]:
#now let's try to connect to it
#we will need the instance IP
instanceIP=!gcloud sql instances describe {instance_name} \
    --format="value[no-heading](ipAddresses.ipAddress)"

instanceIP=instanceIP.s
print(instanceIP)


35.189.65.164

In [111]:
#we will need to authorize our IP to connect to the database
#so let's found my external IP
myExternalIP=!curl -s ipinfo.io/ip
myExternalIP=myExternalIP[0]
print(myExternalIP)


2.152.198.200

In [112]:
#authorize my externalip to connect to my instance
!gcloud sql instances patch --help


NAME
    gcloud sql instances patch - updates the settings of a Cloud SQL instance

SYNOPSIS
    gcloud sql instances patch INSTANCE [--activation-policy=ACTIVATION_POLICY]
        [--assign-ip] [--async] [--cpu=CPU] [--diff] [--enable-bin-log]
        [--enable-database-replication] [--follow-gae-app=FOLLOW_GAE_APP]
        [--gce-zone=GCE_ZONE]
        [--maintenance-release-channel=MAINTENANCE_RELEASE_CHANNEL]
        [--maintenance-window-any]
        [--maintenance-window-day=MAINTENANCE_WINDOW_DAY]
        [--maintenance-window-hour=MAINTENANCE_WINDOW_HOUR] [--memory=MEMORY]
        [--pricing-plan=PRICING_PLAN, -p PRICING_PLAN]
        [--replication=REPLICATION] [--require-ssl] [--storage-auto-increase]
        [--storage-size=STORAGE_SIZE] [--tier=TIER, -t TIER]
        [--authorized-gae-apps=APP,[APP,...] | --clear-gae-apps]
        [--authorized-networks=NETWORK,[NETWORK,...]
          | --clear-authorized-networks]
        [--backup-start-time=BACKUP_START_TIME | --no-backup]
        [--clear-database-flags | --database-flags=FLAG=VALUE,[FLAG=VALUE,...]]
        [GCLOUD_WIDE_FLAG ...]

DESCRIPTION
    Updates the settings of a Cloud SQL instance.

POSITIONAL ARGUMENTS
     INSTANCE
        Cloud SQL instance ID.

FLAGS
     --activation-policy=ACTIVATION_POLICY
        The activation policy for this instance. This specifies when the
        instance should be activated and is applicable only when the instance
        state is RUNNABLE. ACTIVATION_POLICY must be one of: ALWAYS, NEVER,
        ON_DEMAND.

     --assign-ip
        The instance must be assigned an IP address.

     --async
        Do not wait for the operation to complete.

     --cpu=CPU
        A whole number value indicating how many cores are desired in the
        machine. Both --cpu and --memory must be specified if a custom machine
        type is desired, and the --tier flag must be omitted.

     --diff
        Show what changed as a result of the update.

     --enable-bin-log
        Enable binary log. If backup configuration is disabled, binary log
        should be disabled as well.

     --enable-database-replication
        Enable database replication. Applicable only for read replica
        instance(s). WARNING: Instance will be restarted.

     --follow-gae-app=FOLLOW_GAE_APP
        First Generation instances only. The App Engine app this instance
        should follow. It must be in the same region as the instance. WARNING:
        Instance may be restarted.

     --gce-zone=GCE_ZONE
        The preferred Compute Engine zone (e.g. us-central1-a, us-central1-b,
        etc.). WARNING: Instance may be restarted.

     --maintenance-release-channel=MAINTENANCE_RELEASE_CHANNEL
        Which channel's updates to apply during the maintenance window.
        MAINTENANCE_RELEASE_CHANNEL must be one of:

         preview
            Preview updates release prior to production updates. You may wish
            to use the preview channel for dev/test applications so that you
            can preview their compatibility with your application prior to the
            production release.
         production
            Production updates are stable and recommended for applications in
            production.

     --maintenance-window-any
        Removes the user-specified maintenance window.

     --maintenance-window-day=MAINTENANCE_WINDOW_DAY
        Day of week for maintenance window, in UTC time zone.
        MAINTENANCE_WINDOW_DAY must be one of: SUN, MON, TUE, WED, THU, FRI,
        SAT.

     --maintenance-window-hour=MAINTENANCE_WINDOW_HOUR
        Hour of day for maintenance window, in UTC time zone.

     --memory=MEMORY
        A whole number value indicating how much memory is desired in the
        machine. A size unit should be provided (eg. 3072MiB or 9GiB) - if no
        units are specified, GiB is assumed. Both --cpu and --memory must be
        specified if a custom machine type is desired, and the --tier flag must
        be omitted.

     --pricing-plan=PRICING_PLAN, -p PRICING_PLAN
        First Generation instances only. The pricing plan for this instance.
        PRICING_PLAN must be one of: PER_USE, PACKAGE.

     --replication=REPLICATION
        The type of replication this instance uses. REPLICATION must be one of:
        SYNCHRONOUS, ASYNCHRONOUS.

     --require-ssl
        mysqld should default to 'REQUIRE X509' for users connecting over IP.

     --storage-auto-increase
        Storage size can be increased, but it cannot be decreased; storage
        increases are permanent for the life of the instance. With this setting
        enabled, a spike in storage requirements can result in permanently
        increased storage costs for your instance. However, if an instance runs
        out of available space, it can result in the instance going offline,
        dropping existing connections.

     --storage-size=STORAGE_SIZE
        Amount of storage allocated to the instance. Must be an integer number
        of GB between 10GB and 10230GB inclusive.

     --tier=TIER, -t TIER
        The tier for this instance. For Second Generation instances, TIER is
        the instance's machine type (e.g., db-n1-standard-1). For PostgreSQL
        instances, only shared-core machine types (e.g., db-f1-micro) apply. A
        complete list of tiers is available here:
        https://cloud.google.com/sql/pricing. WARNING: Instance will be
        restarted.

    At most one of these may be specified:

     --authorized-gae-apps=APP,[APP,...]
        First Generation instances only. List of IDs for App Engine
        applications running in the Standard environment that can access this
        instance.

     --clear-gae-apps
        Specified to clear the list of App Engine apps that can access this
        instance.

    At most one of these may be specified:

     --authorized-networks=NETWORK,[NETWORK,...]
        The list of external networks that are allowed to connect to the
        instance. Specified in CIDR notation, also known as 'slash' notation
        (e.g. 192.168.100.0/24).

     --clear-authorized-networks
        Clear the list of external networks that are allowed to connect to the
        instance.

    At most one of these may be specified:

     --backup-start-time=BACKUP_START_TIME
        The start time of daily backups, specified in the 24 hour format -
        HH:MM, in the UTC timezone.

     --no-backup
        Specified if daily backup should be disabled.

    At most one of these may be specified:

     --clear-database-flags
        Clear the database flags set on the instance. WARNING: Instance will be
        restarted.

     --database-flags=FLAG=VALUE,[FLAG=VALUE,...]
        A comma-separated list of database flags to set on the instance. Use an
        equals sign to separate flag name and value. Flags without values, like
        skip_grant_tables, can be written out without a value after, e.g.,
        skip_grant_tables=. Use on/off for booleans. View the Instance Resource
        API for allowed flags. (e.g., --database-flags
        max_allowed_packet=55555,skip_grant_tables=,log_output=1)

GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --configuration,
    --flatten, --format, --help, --log-http, --project, --quiet, --trace-token,
    --user-output-enabled, --verbosity. Run $ gcloud help for details.

In [121]:
#authorize my externalip to connect to my instance
!gcloud sql instances patch {instance_name} --quiet \
            --authorized-networks={myExternalIP}


The following message will be used for the patch API method.
{"project": "future-sonar-168815", "name": "instance-toto", "settings": {"ipConfiguration": {"authorizedNetworks": [{"value": "2.152.198.200"}]}}}
Patching Cloud SQL instance...done.                                            
Updated [https://www.googleapis.com/sql/v1beta4/projects/future-sonar-168815/instances/instance-toto].

In [122]:
#let's get some data from a database of this instance
import pymysql
pymysql.install_as_MySQLdb()
conn= pymysql.connect(host=instanceIP,user='root',\
                     passwd=password,db='information_schema')
with conn.cursor() as cur:
    cur.execute("SELECT * FROM tables")
    for r in cur:
            print(r)

conn.close()


('def', 'information_schema', 'CHARACTER_SETS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 384, 0, 16434816, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=43690', '')
('def', 'information_schema', 'COLLATIONS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 231, 0, 16704765, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=72628', '')
('def', 'information_schema', 'COLLATION_CHARACTER_SET_APPLICABILITY', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 195, 0, 16357770, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=86037', '')
('def', 'information_schema', 'COLUMNS', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=2794', '')
('def', 'information_schema', 'COLUMN_PRIVILEGES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2565, 0, 16757145, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=6540', '')
('def', 'information_schema', 'ENGINES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 490, 0, 16574250, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=34239', '')
('def', 'information_schema', 'EVENTS', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=619', '')
('def', 'information_schema', 'FILES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2659, 0, 16743723, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=6309', '')
('def', 'information_schema', 'GLOBAL_STATUS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 3268, 0, 16755036, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=5133', '')
('def', 'information_schema', 'GLOBAL_VARIABLES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 3268, 0, 16755036, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=5133', '')
('def', 'information_schema', 'KEY_COLUMN_USAGE', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 4637, 0, 16762755, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=3618', '')
('def', 'information_schema', 'OPTIMIZER_TRACE', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=578524', '')
('def', 'information_schema', 'PARAMETERS', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=6021', '')
('def', 'information_schema', 'PARTITIONS', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=5596', '')
('def', 'information_schema', 'PLUGINS', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=11328', '')
('def', 'information_schema', 'PROCESSLIST', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=13148', '')
('def', 'information_schema', 'PROFILING', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 308, 0, 16562084, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=54471', '')
('def', 'information_schema', 'REFERENTIAL_CONSTRAINTS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 4814, 0, 16767162, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=3485', '')
('def', 'information_schema', 'ROUTINES', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=583', '')
('def', 'information_schema', 'SCHEMATA', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 3464, 0, 16738048, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=4843', '')
('def', 'information_schema', 'SCHEMA_PRIVILEGES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2179, 0, 16736899, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=7699', '')
('def', 'information_schema', 'SESSION_STATUS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 3268, 0, 16755036, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=5133', '')
('def', 'information_schema', 'SESSION_VARIABLES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 3268, 0, 16755036, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=5133', '')
('def', 'information_schema', 'STATISTICS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 5753, 0, 16752736, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=2916', '')
('def', 'information_schema', 'TABLES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 9441, 0, 16757775, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=1777', '')
('def', 'information_schema', 'TABLESPACES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 6951, 0, 16772763, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=2413', '')
('def', 'information_schema', 'TABLE_CONSTRAINTS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2504, 0, 16721712, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=6700', '')
('def', 'information_schema', 'TABLE_PRIVILEGES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2372, 0, 16748692, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=7073', '')
('def', 'information_schema', 'TRIGGERS', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=569', '')
('def', 'information_schema', 'USER_PRIVILEGES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1986, 0, 16726092, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=8447', '')
('def', 'information_schema', 'VIEWS', 'SYSTEM VIEW', 'MyISAM', 10, 'Dynamic', None, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, 'max_rows=6935', '')
('def', 'information_schema', 'INNODB_LOCKS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 31244, 0, 16746784, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=536', '')
('def', 'information_schema', 'INNODB_TRX', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 4536, 0, 16746912, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=3698', '')
('def', 'information_schema', 'INNODB_SYS_DATAFILES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 12007, 0, 16773779, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=1397', '')
('def', 'information_schema', 'INNODB_LOCK_WAITS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 599, 0, 16749238, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=28008', '')
('def', 'information_schema', 'INNODB_SYS_TABLESTATS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1215, 0, 16763355, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=13808', '')
('def', 'information_schema', 'INNODB_CMP', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 25, 0, 13107200, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=671088', '')
('def', 'information_schema', 'INNODB_METRICS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2994, 0, 16742448, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=5603', '')
('def', 'information_schema', 'INNODB_CMP_RESET', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 25, 0, 13107200, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=671088', '')
('def', 'information_schema', 'INNODB_CMP_PER_INDEX', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1755, 0, 16728660, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=9559', '')
('def', 'information_schema', 'INNODB_CMPMEM_RESET', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 29, 0, 15204352, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=578524', '')
('def', 'information_schema', 'INNODB_FT_DELETED', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 9, 0, 9437184, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=1864135', '')
('def', 'information_schema', 'INNODB_BUFFER_PAGE_LRU', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 6669, 0, 16765866, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=2515', '')
('def', 'information_schema', 'INNODB_SYS_FOREIGN', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1752, 0, 16700064, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=9576', '')
('def', 'information_schema', 'INNODB_SYS_COLUMNS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 610, 0, 16613350, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=27503', '')
('def', 'information_schema', 'INNODB_SYS_INDEXES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 614, 0, 16722290, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=27324', '')
('def', 'information_schema', 'INNODB_FT_DEFAULT_STOPWORD', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 56, 0, 14680064, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=299593', '')
('def', 'information_schema', 'INNODB_SYS_FIELDS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 594, 0, 16609428, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=28244', '')
('def', 'information_schema', 'INNODB_CMP_PER_INDEX_RESET', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1755, 0, 16728660, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=9559', '')
('def', 'information_schema', 'INNODB_BUFFER_PAGE', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 6852, 0, 16766844, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=2448', '')
('def', 'information_schema', 'INNODB_CMPMEM', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 29, 0, 15204352, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=578524', '')
('def', 'information_schema', 'INNODB_FT_INDEX_TABLE', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1054, 0, 16744898, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=15917', '')
('def', 'information_schema', 'INNODB_FT_BEING_DELETED', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 9, 0, 9437184, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=1864135', '')
('def', 'information_schema', 'INNODB_SYS_TABLESPACES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2082, 0, 16728870, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=8058', '')
('def', 'information_schema', 'INNODB_FT_INDEX_CACHE', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1054, 0, 16744898, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=15917', '')
('def', 'information_schema', 'INNODB_SYS_FOREIGN_COLS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1748, 0, 16738848, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=9597', '')
('def', 'information_schema', 'INNODB_SYS_TABLES', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 2060, 0, 16743680, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=8144', '')
('def', 'information_schema', 'INNODB_BUFFER_POOL_STATS', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 257, 0, 16332350, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=65280', '')
('def', 'information_schema', 'INNODB_FT_CONFIG', 'SYSTEM VIEW', 'MEMORY', 10, 'Fixed', None, 1163, 0, 16705332, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 54, 48), None, None, 'utf8_general_ci', None, 'max_rows=14425', '')
('def', 'mysql', 'columns_priv', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 227994731135631359, 4096, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_bin', None, '', 'Column privileges')
('def', 'mysql', 'db', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 123848989752688639, 2048, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_bin', None, '', 'Database privileges')
('def', 'mysql', 'event', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 0, 0, 0, 281474976710655, 2048, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'Events')
('def', 'mysql', 'func', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 162974011515469823, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_bin', None, '', 'User defined functions')
('def', 'mysql', 'general_log', 'BASE TABLE', 'CSV', 10, 'Dynamic', 2, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', 'General log')
('def', 'mysql', 'heartbeat', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 1, 13, 13, 3659174697238527, 2048, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 41), datetime.datetime(2017, 7, 1, 11, 54, 48), None, 'utf8_general_ci', None, '', '')
('def', 'mysql', 'help_category', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 0, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'help categories')
('def', 'mysql', 'help_keyword', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 55450570411999231, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'help keywords')
('def', 'mysql', 'help_relation', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 2533274790395903, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'keyword-topic relation')
('def', 'mysql', 'help_topic', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 0, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'help topics')
('def', 'mysql', 'innodb_index_stats', 'BASE TABLE', 'InnoDB', 10, 'Compact', 0, 0, 16384, 0, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 39), None, None, 'utf8_bin', None, 'stats_persistent=0', '')
('def', 'mysql', 'innodb_table_stats', 'BASE TABLE', 'InnoDB', 10, 'Compact', 0, 0, 16384, 0, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), None, None, 'utf8_bin', None, 'stats_persistent=0', '')
('def', 'mysql', 'ndb_binlog_index', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 0, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', '')
('def', 'mysql', 'plugin', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 0, 0, 0, 281474976710655, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'MySQL plugins')
('def', 'mysql', 'proc', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 0, 0, 0, 281474976710655, 2048, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'Stored Procedures')
('def', 'mysql', 'procs_priv', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 239253730204057599, 4096, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_bin', None, '', 'Procedure privileges')
('def', 'mysql', 'proxies_priv', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 195062158860484607, 2048, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 41), datetime.datetime(2017, 7, 1, 11, 40, 41), None, 'utf8_bin', None, '', 'User proxy privileges')
('def', 'mysql', 'servers', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 433752939111120895, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'MySQL Foreign Servers table')
('def', 'mysql', 'slave_master_info', 'BASE TABLE', 'InnoDB', 10, 'Compact', 0, 0, 16384, 0, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 40), None, None, 'utf8_general_ci', None, 'stats_persistent=0', 'Master Information')
('def', 'mysql', 'slave_relay_log_info', 'BASE TABLE', 'InnoDB', 10, 'Compact', 0, 0, 16384, 0, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 40), None, None, 'utf8_general_ci', None, 'stats_persistent=0', 'Relay Log Information')
('def', 'mysql', 'slave_worker_info', 'BASE TABLE', 'InnoDB', 10, 'Compact', 0, 0, 16384, 0, 0, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 40), None, None, 'utf8_general_ci', None, 'stats_persistent=0', 'Worker Information')
('def', 'mysql', 'slow_log', 'BASE TABLE', 'CSV', 10, 'Dynamic', 2, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', 'Slow log')
('def', 'mysql', 'system_user', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 3, 94, 284, 281474976710655, 2048, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 41), datetime.datetime(2017, 7, 1, 11, 40, 41), None, 'utf8_bin', None, '', 'System user accounts and their global privileges')
('def', 'mysql', 'tables_priv', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 239535205180768255, 4096, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_bin', None, '', 'Table privileges')
('def', 'mysql', 'time_zone', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 1777, 7, 12439, 1970324836974591, 20480, 0, 1778, datetime.datetime(2017, 7, 1, 11, 40, 41), datetime.datetime(2017, 7, 1, 11, 40, 51), None, 'utf8_general_ci', None, '', 'Time zones')
('def', 'mysql', 'time_zone_leap_second', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 0, 0, 0, 3659174697238527, 1024, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 40, 38), None, 'utf8_general_ci', None, '', 'Leap seconds information for time zones')
('def', 'mysql', 'time_zone_name', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 1777, 197, 350069, 55450570411999231, 51200, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 41), datetime.datetime(2017, 7, 1, 11, 40, 51), None, 'utf8_general_ci', None, '', 'Time zone names')
('def', 'mysql', 'time_zone_transition', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 120208, 17, 2043536, 4785074604081151, 2273280, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 51), datetime.datetime(2017, 7, 1, 11, 40, 53), None, 'utf8_general_ci', None, '', 'Time zone transitions')
('def', 'mysql', 'time_zone_transition_type', 'BASE TABLE', 'MyISAM', 10, 'Fixed', 8293, 38, 315134, 10696049115004927, 121856, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 53), datetime.datetime(2017, 7, 1, 11, 40, 53), None, 'utf8_general_ci', None, '', 'Time zone transition types')
('def', 'mysql', 'user', 'BASE TABLE', 'MyISAM', 10, 'Dynamic', 1, 108, 108, 281474976710655, 2048, 0, None, datetime.datetime(2017, 7, 1, 11, 40, 38), datetime.datetime(2017, 7, 1, 11, 50, 13), None, 'utf8_bin', None, '', 'Users and global privileges')
('def', 'performance_schema', 'accounts', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Fixed', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'cond_instances', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_current', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_history', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_history_long', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 10000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_summary_by_account_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_summary_by_host_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_summary_by_thread_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_summary_by_user_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_stages_summary_global_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_current', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_history', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_history_long', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 10000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_summary_by_account_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_summary_by_digest', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_summary_by_host_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_summary_by_thread_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_summary_by_user_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_statements_summary_global_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_current', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_history', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_history_long', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 10000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_summary_by_account_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_summary_by_host_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_summary_by_instance', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_summary_by_thread_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_summary_by_user_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'events_waits_summary_global_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'file_instances', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'file_summary_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'file_summary_by_instance', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'host_cache', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'hosts', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Fixed', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'mutex_instances', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'objects_summary_global_by_type', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'performance_timers', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Fixed', 5, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'rwlock_instances', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'session_account_connect_attrs', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_bin', None, '', '')
('def', 'performance_schema', 'session_connect_attrs', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_bin', None, '', '')
('def', 'performance_schema', 'setup_actors', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Fixed', 0, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'setup_consumers', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 12, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'setup_instruments', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'setup_objects', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 0, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'setup_timers', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 4, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'socket_instances', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'socket_summary_by_event_name', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'socket_summary_by_instance', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'table_io_waits_summary_by_index_usage', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'table_io_waits_summary_by_table', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'table_lock_waits_summary_by_table', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'threads', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Dynamic', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')
('def', 'performance_schema', 'users', 'BASE TABLE', 'PERFORMANCE_SCHEMA', 10, 'Fixed', 1000, 0, 0, 0, 0, 0, None, None, None, None, 'utf8_general_ci', None, '', '')

In [123]:
#we take out the network authorizations
!gcloud sql instances patch {instance_name} --quiet \
            --clear-authorized-networks


The following message will be used for the patch API method.
{"project": "future-sonar-168815", "name": "instance-toto", "settings": {"ipConfiguration": {"authorizedNetworks": []}}}
Patching Cloud SQL instance...done.                                            
Updated [https://www.googleapis.com/sql/v1beta4/projects/future-sonar-168815/instances/instance-toto].

In [124]:
#let's have a look a my instances
!gcloud sql instances list


NAME           REGION        TIER         ADDRESS        STATUS
instance-toto  europe-west2  db-f1-micro  35.189.65.164  RUNNABLE

In [125]:
#Let's do some clean-up
#some help
!gcloud sql instances delete --help


NAME
    gcloud sql instances delete - deletes a Cloud SQL instance

SYNOPSIS
    gcloud sql instances delete INSTANCE [--async] [GCLOUD_WIDE_FLAG ...]

DESCRIPTION
    Deletes a Cloud SQL instance.

POSITIONAL ARGUMENTS
     INSTANCE
        Cloud SQL instance ID.

FLAGS
     --async
        Display information about the operation in progress, without waiting
        for the operation to complete.

GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --configuration,
    --flatten, --format, --help, --log-http, --project, --quiet, --trace-token,
    --user-output-enabled, --verbosity. Run $ gcloud help for details.

In [126]:
#let's do it
instancesList=!gcloud sql instances list --format="value[no-heading](name)"
for instance in instancesList:
    if input("Please confirm that you want to delete the instance %s by entering Yes?"%instance) == "Yes":
        print("Deleting instance %s"%instance)
        !gcloud sql instances delete --quiet {instance}


Please confirm that you want to delete the instance instance-toto by entering Yes?Yes
Deleting instance instance-toto
Deleting Cloud SQL instance...done.                                            
Deleted [https://www.googleapis.com/sql/v1beta4/projects/future-sonar-168815/instances/instance-toto].

In [ ]: