Importing Data into Cloud SQL

This page describes how to import data into Google Cloud SQL using a SQL dump file.

Before you begin

Before you can use the import features of Cloud SQL, you must satisfy the following requirements:

Importing SQL dump files from Cloud Storage

To import SQL dump files from Cloud Storage:

Console

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

    Go to the Cloud SQL Instances page

  2. Select the instance to which you want to import a SQL dump file.
  3. Click Import in the button bar.
  4. Choose the file to import into your Cloud SQL instance.

    You can use a compressed (.gz) or an uncompressed (.sql) file.

  5. Provide the name of the database you want to import the data into.

    The database must already exist.

  6. Click Import to start the import.

gcloud

To import a dump file from a Google Cloud Storage bucket to an instance:

  1. Describe the instance you are importing to:
    gcloud beta sql instances describe [INSTANCE_NAME]
    
  2. Copy the serviceAccountEmailAddress field.
  3. Add the service account to the bucket ACL as a writer:
    gsutil acl ch -u [SERVICE_ACCOUNT_ADDRESS]:W gs://[BUCKET_NAME]
    
  4. Add the service account to the import file as a reader:
    gsutil acl ch -u [SERVICE_ACCOUNT_ADDRESS]:R gs://[BUCKET_NAME]/[IMPORT_FILE_NAME]
    
  5. Import the database:
    gcloud beta sql instances import [INSTANCE_NAME] gs://[BUCKET_NAME]/[IMPORT_FILE_NAME] --database [DATABASE_NAME]
    

    For information about using the import command, see the sql instances import command reference page.

  6. Remove the service account from the file and bucket ACLs:
    gsutil acl ch -d [SERVICE_ACCOUNT_ADDRESS] gs://[BUCKET_NAME]/[IMPORT_FILE_NAME]
    gsutil acl ch -d [SERVICE_ACCOUNT_ADDRESS] gs://[BUCKET_NAME]
    

    This step is strongly recommended for security.

What's next

Send feedback about...

Cloud SQL for PostgreSQL