Importing and exporting data to and from your instances allows you to move databases from one instance to another. This is especially useful if you are migrating your data to Google Cloud SQL instances.
To learn more about the requirements and best practices for importing and exporting data, see Overview of Importing and Exporting Data.
For both importing and exporting, make sure the relevant permissions are set up. An instance’s "Service Account Email Address" must be added to the object’s permission, if it’s in a Google Cloud Storage bucket (for importing), or the bucket’s permission (for exporting) as an “OWNER”.
This email is stored in the following snippet:
$instance = Get-GcSqlOperation -Instance "mynewinstance" $serviceEmail = $instance.ServiceAccountEmailAddress
Importing SQL and CSV files
You can import an existing SQL dump or CSV file into an existing database inside of your Cloud SQL instances. This file must be either on your local machine or in a Cloud Storage bucket.
The following snippet imports the data in a local CSV file into the table "destinationTable" inside of the database "destinationDatabase" in the Cloud SQL instance "gootoso":
Import-GcSqlInstance "gootoso" "C:\Users\User\file.csv" ` "destinationDatabase" "destinationTable"
Similarly, if a MySQL dump file is already in a Cloud Storage bucket, you can import it into the database "destinationDatabase" of a specified instance. For example:
Import-GcSqlInstance "gootoso" "gs://bucket/file.gz" ` "destinationDatabase"
Exporting SQL and CSV files
You can export existing databases in a Cloud SQL instance into an existing Cloud Storage Bucket for further analysis, importing into other instances, and so on.
The following code snippit exports the database's "guestbook" and "Purchases" from the instance "gootoso" into a compressed file in a Cloud Storage bucket. To export all databases to a compressed
.gz SQL dump file, call:
Export-GcSqlInstance "gootoso" "gs://bucket/file.gz" ` -Databases "guestbook","Purchases"