title: GAE Python - OperationalError: (2013, 'Lost connection to MySQL server during query')
body: <p>I've been trying to connect to ClouSQL using Flexible Environments (vm:true)</p>
  
  <p>but when I upload  my app using:</p>
  
  <pre><code>gcloud preview app deploy --version MYVERSION
  </code></pre>
  
  <p>An error is thrown:</p>
  
  <pre><code>OperationalError: (2013, 'Lost connection to MySQL server during query')
  </code></pre>
  
  <p>I found out that it might be because the query is too large but I think that's not the case because it works locally and on production when I wans't using flexible environments with MySQLdb.</p>
  
  <p>My code: </p>
  
  <pre><code>import os
  import logging
  import pymysql
  
  class MySQL(object):
      '''
      classdocs
      '''
      # TO INSTALL LOCAL DB: http://stackoverflow.com/questions/30893734/no-module-named-mysql-google-app-engine-django
  
  
      @classmethod
      def getConnection(cls):
          # When running on Google App Engine, use the special unix socket
          # to connect to Cloud SQL.
          if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
              logging.debug('PROJECT [%s], INSTANCE[%s] - USER [%s] - PASS [%s], SCHEMA [%s]',
                            os.getenv('CLOUDSQL_PROJECT'),
                            os.getenv('CLOUDSQL_INSTANCE'),
                            os.getenv('CLOUDSQL_USER'),
                            os.getenv('CLOUDSQL_PASS'),
                            os.getenv('CLOUDSQL_SCHEMA'))
  
              db = pymysql.connect(unix_socket='/cloudsql/APP:REGION:INSTANCENAME')
                      #os.getenv('CLOUDSQL_PROJECT'),
                      #os.getenv('CLOUDSQL_INSTANCE')), 
                      #user=os.getenv('CLOUDSQL_USER'),
                      #passwd=os.getenv('CLOUDSQL_PASS'),  
                      #db=os.getenv('CLOUDSQL_SCHEMA'))
          # When running locally, you can either connect to a local running
          # MySQL instance, or connect to your Cloud SQL instance over TCP.
          else:
              db = pymysql.connect(host=os.getenv('DBDEV_HOST'), user=os.getenv('DBDEV_USER'), 
                                   passwd=os.getenv('DBDEV_PASS', ''), db=os.getenv('DBDEV_SCHEMA'))
  
          return db
  </code></pre>
  
  <p>Any thoughts on this?</p>
  
  <p>Thanks!</p>