Reputation: 61
I'm new to cloudSQL, trying to build a small console application to test the functionalities of CLoudSQL API. (google-api-services-sqladmin - v1beta4)
Can somebody help me to get start with some sample code?
For example, i want to export data from cloudSQL to GCS using - select query?
Upvotes: 0
Views: 356
Reputation: 3579
Here's a sample HTTP request that will export the table mysql.user
to a CSV file in Cloud Storage:
POST https://www.googleapis.com/sql/v1beta4/projects/<project>/instances/<instance>/export
content-type: application/json
content-length: <length-of-request-body>
Authorization: Bearer <access-token>
{
"exportContext": {
"csvExportOptions": {
"selectQuery": "SELECT * FROM mysql.user"
},
"uri": "gs://<bucket>/users.csv",
"fileType": "CSV"
}
}
Note that you need to set the values for <project>
, <instance>
, <access-token>
, and <bucket>
.
Once you have those parameters, you can easily try this either using the API Explorer, at the bottom where it says "try it".
Or simply by using curl
:
CURL command:
$ curl -X POST \
https://www.googleapis.com/sql/v1beta4/projects/<project>/instances/<instance>/export \
-H'content-length: <length-of-request-body>'
-H'content-type: application/json'
-H'Authorization: Bearer <access-token>'
-d'{"exportContext": {"csvExportOptions": {"selectQery": "SELECT * FROM mysql.user"}, "fileType": "CSV", "uri": "gs://<bucket>/users.csv"}}'
Upvotes: 1