I was trying to access the mysql databases from server A to server “apple” using the Python Django. The relevant statements are
import settings
os.environ['DJANGO_SETTINGS_MODULE'] = runconfig.django_settings_module
from django.db import connection
class Writer(object):
def __init__(self):
def submission(self,pars):
d = connection.cursor()
and running this gives me the error as below:
_mysql_exceptions.OperationalError: (1044, "Access denied for user 'username'@'ice.cse.connell.edu' to database 'mydatabase'")
The content of runconfig.py is
# Django setting module
django_settings_module = 'settings'
Strangely, I am able to login to mysql from server “ice” to server “apple” remotely:
$ mysql -u username -ppassword -h apple
I have been digging this problem from SO but still cannot find an answer. This question has been driven me crazy!
Below is the first few lines of my settings.py. Because it is too long, I did not post all of it. But if any one needs more, I can paste all the content.
# Django settings for mydatabase project.
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mydatabase' # Or path to database file if using sqlite3.
DATABASE_USER = 'username' # Not used with sqlite3.
DATABASE_PASSWORD = 'password' # Not used with sqlite3.
DATABASE_HOST = 'apple' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
—————————————————————————————–
APPENDED POST
After modifying the settings.py based on Sid’s suggestion:
#DATABASE_ENGINE = 'mysql'
#DATABASE_NAME = 'mydatabase'
#DATABASE_USER = 'username'
#DATABASE_PASSWORD = 'password'
#DATABASE_HOST = 'apple'
#DATABASE_PORT = ''
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydatabase',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'apple',
'PORT': '',
}
}
The command line inputs and error messages are
>>> import runconfig
>>>
>>> import os
>>> import sys
>>> import settings
>>> #from django.conf import settings
...
>>> os.environ['DJANGO_SETTINGS_MODULE'] = runconfig.django_settings_module
>>>
>>> from django.db import connection
>>> c = connection.cursor()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured, "You haven't set the DATABASE_ENGINE setting yet."
django.core.exceptions.ImproperlyConfigured: You haven't set the DATABASE_ENGINE setting yet.
Check your database name, it may be case-sensitive.
http://groups.google.com/group/django-users/browse_thread/thread/8717661c908b836e
Try Using the following format:
Also, does the username you are using have privileges to this database?