Add data to Google Cloud SQL from Google Compute Engine using python

109 views
Skip to first unread message

Roberto Catalán

unread,
Apr 11, 2019, 4:30:33 PM4/11/19
to Google Cloud SQL discuss
I need to be able to send data from GCE (Google compute engine) to a Table in Google Cloud SQL

Reding the documentation i found:

from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()
service = discovery.build('sqladmin', 'v1beta4', credentials=credentials)

project  = 'xx1'   # TODO: Update placeholder value.
instance = 'xx2'   # TODO: Update placeholder value.
database = 'xx3'   # TODO: Update placeholder value.

And with this documentation link , i did could get the information of users and all database created in Google Cloud SQL (It worked)

users       = service.users().list(project=project, instance=instance).execute()
pprint(users)  # List of user 

all_databases   = service.databases().list(project=project, instance=instance).execute()
pprint(all_databases)


My question is:
I have a Database created in Google Cloud SQL
I have a Table created in the Database

How can i insert data to the Table from Google Compute Engine? I cannot find documentation. Could anyone help me?

Regards....






George (Cloud Platform Support)

unread,
Apr 13, 2019, 11:57:56 AM4/13/19
to Google Cloud SQL discuss
Hello Roberto, 

You don't mention connecting to the Cloud SQL instance. Just in case, if this may prove problematic, you have access to related information on the "Connecting MySQL Client from Compute Engine" documentation page

To insert data in a table, you simply use SQL commands. A useful example can be read in the "Insert sample data into the guestbook database" sub-chapter of the "Quickstart for Cloud SQL for MySQL" page. 

You should post such questions to StackOverflow, or other similar forums. This forum meant for general discussion on the platform and its services. By contrast, in StackOverflow, you get in contact with experienced programmers with MySQL experience, who are happy to help. 
Reply all
Reply to author
Forward
0 new messages