title: Query Cloud SQL Database from Python
body: <p>I want to insert data into a <a href="https://cloud.google.com/sql/" rel="nofollow">CloudSQL</a> MySQL database from a local Python application, is this possible, if so how?</p>
  
  <p>I have tried running the examples at the bottom of <a href="https://cloud.google.com/appengine/docs/python/cloud-sql/#Python_complete_python_example" rel="nofollow">https://cloud.google.com/appengine/docs/python/cloud-sql/#Python_complete_python_example</a></p>
  
  <pre><code>db = MySQLdb.connect(unix_socket='/cloudsql/PROJECT-ID:INSTANCE-NAME', user='phil')
  
  cursor = db.cursor()
  cursor.execute('SHOW VARIABLES')
  for r in cursor.fetchall():
    webapp2.RequestHandler.response.write('%s\n' % str(r))
  
  db.close()
  </code></pre>
  
  <p>However I get the error: </p>
  
  <pre><code>`Can't connect to local MySQL server through socket`
  </code></pre>