I'm facing problem while connecting mysql database in django. I'm getting error as
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: DLL load failed: %1 is not a valid Win32 application.
I have set database setting as
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
I don't know where I'm making mistake.
Probably you are using 64bit python/mysql but pip had installed the 32bit mysql-python.
Download the 64bit mysql-python from the link [The link only has support for python 2.7]:
http://www.codegood.com/archives/129
and run the following:
$ pip install path_to_64bit-mysql-python.zip
Related
This message showed after I executed runserver command:
System check identified no issues (0 silenced)
I have referenced this solution, but it didn't work for me(I start my mysql server by the command
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld"
).
Here is the background information(the "pip list" command):
(DjangoEnv) D:\pythonproject\DjangoEnv\loginoutonly>pip list
Package Version
Django 2.1.5
mysqlclient 1.3.13
pip 18.1
PyMySQL 0.9.3
pytz 2018.9
setuptools 40.6.3
wheel 0.32.3
Here is the db information in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'loginoutonly',
'USER': 'root',
'PASSWORD': 'pwd',
'HOST': 'localhost',
'PORT': '3306'
}
}
XAMPP helped me.
XAMPP says that
Port 3306 in use by "Unable to open process"!
I change my MySQL port to 3307 using XAMPP [Config] button.
Then, I change my settings.py code to
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'loginoutonly',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3307'
}
}
I also need to test the MySQL WorkBench connection of this newly connected port "3307".
I'm a Django newby (I started yesterday) and I'm trying to configure the DB. But since I think I'll always be using Django with MySQL I want to set it up. I read the doc and I saw that in order to use MySQL you have to install a module, and so I did. I installed mysqlclient since installing MySQLdb with pip return:
$ pip2 install mysqldb
Could not find a version that satisfies the requirement mysqldb (from versions: )
No matching distribution found for mysqldb
and the Oracle solution isn't working at all (django don't recognize it).
So I entered my credentials, and it look like this in project's settings.py:
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname_entered_and_tested',
'USER': 'username_entered_and_tested',
'PASSWORD': 'correct_password',
'HOST': 'externale.domain_name_to_db.com',
'PORT': '3306',
}
}
So it returned me
$ python manage.py runserver
... 30 lines of Exceptions ...
django.db.utils.OperationalError: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')
So I googled and I found Django AWS RDS MySQL Error: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')
So I set my settings to:
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname_entered_and_tested',
'USER': 'username_entered_and_tested',
'PASSWORD': 'correct_password',
'HOST': 'externale.domain_name_to_db.com',
'PORT': '3306',
'OPTIONS': {
'skip-ssl',
},
}
}
And it returned me
$ python manager.py runserver
... 30 lines of Exceptions ...
ValueError: dictionary update sequence element #0 has length 8; 2 is required
So I managed to generate my own certificats after reading another stackoverflow post, using OpenSSL and the MySQL doc (https://dev.mysql.com/doc/refman/5.6/en/creating-ssl-files-using-openssl.html) and I succeded, but django threw the same:
django.db.utils.OperationalError: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')
I already tried connecting with multiple other clients to my db using the same credentials, disabling SSL, enabling SSL, another user account.
I found a solution but it involve downgrading the MySQL version to 5.6.27 (Django server not starting correctly seems to be a mysql issue.) and it won't be a problem... if I only could :C . The MySQL database since to be a pain for a lot of Django users (so much post talking about that out there ...) and I'm just a newbie but I don't want to be discouraged by a simple bug and stop Django :S So, does someone have an answer ?
EDIT: I'm using the latest version of both django, pip and mysqlclient
I am creating a Django project based on PostGreSql on Windows OS.
I could successfully download Postgresql (32bits) and psycopg2. I work on a 32 bit Python2.7.9 , and my Postgresql - 9.3.7 32-bits.
import psycopg2 throws NO error.
I could find a psycopg2 folder in Python27\Lib\site-packages
My settings.py contains the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'testdb' ,
'USER': 'postgres',
'PASSWORD': 'paggu',
'HOST': 'localhost',
'PORT': '5432',
}
}
But I still get the below error when I try to execute the command- python manage.py runserver or python manage.py syncdb
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: DLL
load failed: The specified module could not be found.
I am not sure if I missed on anything.
I looked up on the other Stack Overflow posts regarding this problem but didn't seem to find any solution.
You may need to actually install psycopg2. To find out run the following in a Windows command prompt:
C:\path\to\project\> python
Then:
>>> help("modules")
If psycopg2 is not in the list, do the following:
Download: psycopg2-2.6.2.win32-py2.7-pg9.5.3-release.exe from HERE, then run the following in a Windows command prompt:
C:\path\to\project> easy_install /path/to/psycopg2-2.6.2.win32-py2.7-pg9.5.3-release.exe
I would like to use the PostGreSQL database with Django.
I first installed the driver psycopg2 with pip and virtualenv:
$ PATH=$PATH:/Library/PostgreSQL/9.3/bin/
$ pip install psycopg2
[...]
Successfully installed psycopg2
Cleaning up...
$
I have done the following configuration in Django:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_db',
'USER': 'django',
'PASSWORD': 'xx',
'HOST': 'localhost',
'PORT': '5432',
}
}
But when I try to create the schema with syncdb I have the following error:
$ python manage.py syncdb
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen([...]/Code/env/dev/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: [...]Code/env/dev/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
Do you know why the libssl is not loaded and how can I fix this issue?
Thank you
I have successfully followed the Django 1.4 Tutorial 1-4 (the poll system) and now its running until I deploy it in Apache Webserver 2.2 using Postgres Database. Everytime I access localhost I always have "Internal Server Error" but if I use MySQL as my database everything is ok. What do you think is wrong? Did I miss something to configure in Postgre?
Here is my database connection settings in Mysql(Working) and in Postgre(Not Working), both using Apache2.2 + mod_wsgi.so
//Postgre
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_demo1',
'USER': 'postgres',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '',
}
}
//MySQL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_demo1',
'USER': 'root',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '',
}
}
Other INFO:
OS: windows 7, Python: 2.7, Django: 1.4, Postgre 9.1
If you are able to access MySQL but not Postgres, I guess psycopg2 which is the Postgres adapter for python is not installed. Install psycopg2 using pip.
pip install psycopg2
Here is the pypi.