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:
- Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
- Select the instance to which you want to import a SQL dump file.
- Click Import in the button bar.
- Choose the file to import into your Cloud SQL instance.
You can use a compressed (
.gz) or an uncompressed (
- Provide the name of the database you want to import the data into.
The database must already exist.
- Click Import to start the import.
To import a dump file from a Google Cloud Storage bucket to an instance:
- Describe the instance you are importing to:
gcloud beta sql instances describe [INSTANCE_NAME]
- Copy the serviceAccountEmailAddress field.
- Add the service account to the bucket ACL as a writer:
gsutil acl ch -u [SERVICE_ACCOUNT_ADDRESS]:W gs://[BUCKET_NAME]
- 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]
- 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 importcommand reference page.
- 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.
- Learn how to check the status of import and export operations.