pazucj pazucj - 1 year ago 46
MySQL Question

django + own database switch MySQL error

Hello Im changed my database in settings.py from default sqlite to mysql and I got problem. I installed mysqlclient, mysql-python on virtualenv and it's doesnt work

My example database connection

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'dev.website.eu',
'USER': 'name',
'PASSWORD': 'password',
'NAME': 'database_name',

},
'sqlite': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}


}

When I changed database i got a error in terminal

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: libmysqlclient.so.20: cannot open shared object file:
No such file or directory.
Did you install mysqlclient or MySQL-python?


Anyone know how to change that error? If I put those data in mysql-connector it's work but when I want connect via settings.py it doesnt work

Answer Source

First, if you don't need it anymore, remove :

 'sqlite': {
     'ENGINE': 'django.db.backends.sqlite3',
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
 }

Then, what version of Python do you use ?

A more complete conf :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '**',
        'USER': '***',
        'PASSWORD': '***',
        'HOST': 'localhost',
        'PORT': '5432',
        'OPTIONS': {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
        },        
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download