Issue
Update 2022
There is cloud sql proxy now:
https://cloud.google.com/sql/docs/mysql/sql-proxy#how-works
Old Question
I am currently using my local machine to manipulate data, google app engine to host my web service and google cloud sql to handle the database. However, I need to upload my data to gae first, then run a backend job on gae to uploading all data to google cloud sql later. It is time wasting to upload data twice. I would like to import/update some date from my local machine to google cloud sql directly.
Right now, google cloud sql only fully supported google app engine as its client.
Google Cloud SQL is currently only available to Google App Engine applications. To develop Google App Engine applications, you need to install the App Engine SDK, available in either Python or Java:
However, since google cloud sql provides a jar db driver to allow command line client / SQuirrel SQL Client access from local machine. It looks like I can write some java code to interact with the cloud sql via this jar in local machine. Or I could use tools like jpype to access google cloud sql via python.
Is that possible? Where should I start? Or is there any alternative way that I can use python on local machine to access google cloud sql?
https://developers.google.com/cloud-sql/docs/commandline
Solution
I found a way to connect google cloud sql from python via SDK
def connect_sql(instance, database = None):
from google.storage.speckle.python.tool import google_sql
database = google_sql.DatabaseConfig(instance, database)
sql_cmd_config = google_sql.config.SQLCmdConfig(None)
sql_cmd_config.add('__googlesql__', instance, None, None, database,
google_sql.GoogleSqlDriver.NAME, None, None)
sql_cmd = google_sql.GoogleSqlCmd(sql_cmd_config)
sql_cmd.set_database(instance)
sql_cmd.preloop()
return sql_cmd._SQLCmd__db
Answered By - lucemia
Answer Checked By - Senaida (JavaFixing Volunteer)