Search code examples
pythonmysqldjangogoogle-app-enginegoogle-cloud-sql

Not able to use mysql in google app engine - Error loading MySQLdb module: No module named _mysql. I am using cloudSQL


I am using googleAppEngineLauncher to try mysql connection.

It gives the log

 File "/Users/kakshilshah/Desktop/hope/skeduleBackend/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/Users/kakshilshah/Desktop/hope/skeduleBackend/django/db/backends/mysql/base.py", line 17, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named _mysql

I have done pip install MySQL-python

Even commands like python manage.py dbshell works, and connects me to the cloudsql backend.

I can access all the tables there.

But, running it gives the same error.

I have mysql 5.6 installed.

Adding the following to app.yaml

- name: MySQLdb
  version: "latest"

also does not help, because I checked the libraries directory and there was no mysqldb.

My settings -

import os

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
            'HOST': '173.194.xxx.xxx',
            'NAME': 'my_database',
            'USER': 'root',
            'PASSWORD': 'xxxxxxxx',
    }
}

Stuck here, please help.


Solution

  • You cannot have MySQL-python while uploading. Remove that and then upload.

    Just the YAML file's

    - name: MySQLdb
      version: "latest"
    

    Will do, if you add both, it causes a clash.

    It runs locally because it does not consider the YAML's sqldb connector.

    Hope this helps!