accessing cloud storage from cloud sql

31 views
Skip to first unread message

BIRAJ RATH

unread,
Jan 9, 2018, 12:04:15 PM1/9/18
to Google Cloud SQL discuss
Is there a way in which we can export the content of a cloud sql table to cloud storage (as CSV) using sql commands? 

I understand there is an export option using which this can be done but i am wondering can we do that by specifying the bucket name and  file name in the sql command itself. 

regards
Biraj

nau...@google.com

unread,
Jan 9, 2018, 2:19:03 PM1/9/18
to Google Cloud SQL discuss
Hello Biraj

It seems, it is not possible through the SQL command. However, you can use 'gcloud' command to export the data the table data from Cloud SQL instance to the Google cloud storage bucket. Here is the documentation link for the command. 

Example commands: 
[1]
gcloud sql instances export <DATABASE_INSTANCE> \
    gs://<CLOUD_STORAGE_BUCKET>/export.sql.gz \
    --database <DATABASE_NAME>
[2]
gcloud sql instances export <DATABASE_INSTANCE> gs://<CLOUD_STORAGE_BUCKET>/filename.csv --database <DATABASE_NAME> -t <table-name> 

Also can check this thread as the reference. 

Note: Cloud SQL instance service-account must have appropriate access to the bucket to that service account in order for the export/import to work. You can get the service-account of the SQL instance using the command: gcloud sql instances describe instance-name or from the Cloud SQL instance overview page. 
Reply all
Reply to author
Forward
0 new messages