Exporting Data from Cloud SQL

This page describes how to export data from Google Cloud SQL to Google Cloud Storage. You can then download your data from Cloud Storage to your local environment if you want to access it locally.

Exporting data to a SQL dump file

Console

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

    Go to the Cloud SQL Instances page

  2. Click the instance you want to export data from to open its Instance details page.
  3. Click Export in the button bar.
  4. Under Cloud Storage file, choose where to save your export in Google Cloud Storage.
  5. Enter the name of the database you want to export.
  6. Click Export to start the export.

gcloud

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

  1. Create a bucket for the export:
    gsutil mb -p [PROJECT_NAME] -l [LOCATION_NAME] gs://[BUCKET_NAME]
    

    This step is not required, but strongly recommended, so you do not open up access to any other data.

  2. Describe the instance you are exporting from:
    gcloud sql instances describe [INSTANCE_NAME]
    
  3. Copy the serviceAccountEmailAddress field.
  4. Add the service account to the bucket ACL as a writer:
    gsutil acl ch -u [SERVICE_ACCOUNT_ADDRESS]:W gs://[BUCKET_NAME]
    
  5. Export the database:
    gcloud sql instances export [INSTANCE_NAME] gs://[BUCKET_NAME]/sqldumpfile.gz --database [DATABASE_NAME]
    

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

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

    This step is strongly recommended for security.

cURL

  1. Create a bucket for the export:
    gsutil mb -p [PROJECT_NAME] -l [LOCATION_NAME] gs://[BUCKET_NAME]
    

    This step is not required, but strongly recommended, so you do not open up access to any other data.

  2. Provide your instance with write permissions to your bucket.

    For help with setting ACLs, see Setting ACLs.

  3. Export your database:
    ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{"exportContext":
                    {"fileType": "SQL",
                     "uri": "gs://<BUCKET_NAME>/<PATH_TO_DUMP_FILE>",
                     "databases": ["<DATABASE_NAME1>", "<DATABASE_NAME2>"] }}' \
       -X POST \
       https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/export
    
  4. Remove the ACLs you set in the previous step.

    This step is strongly recommended for security.

For the complete list of parameters for this request, see the instances:export page.

What's next

Send feedback about...

Cloud SQL for PostgreSQL