Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got Apache and mod_wsgi up and running, and am now trying to introduce Django to MySQL.

I've created a database named 'django' and a 'django' user; and I've granted all to django on django:

grant ALL on django.* to 'django'@'localhost';

Django's settings.py has been configured with MySQL's settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'django': '',                      # Or path to database file if using sqlite3.
        'django': '',                      # Not used with sqlite3.
        '<a password>': '',                  # Not used with sqlite3.
        '': '',                      # Set to empty string for localhost. Not used with sqlite3.
        '': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

However when I try to run syncdb (python manage.py syncdb) I get:

raceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 219, in execute
    self.validate()
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.6/site-packages/django/core/management/validation.py", line 102, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 338, in get_server_version
    self.cursor()
  File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py", line 250, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 322, in _cursor
    self.connection = Database.connect(**kwargs)
  File "/usr/lib/python2.6/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'ec2-user'@'localhost' (using password: NO)")

The last line has me baffled. I'm not sure why it's trying to connect as ec2-user instead of Django.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You know, I'm not certain why it would default to ec2-user, (unless that happens to be the owner of the process which is running Django), but that config file is far from standard. I believe you want:

default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME':'django',                      # Or path to database file if using sqlite3.
        'USER':'django',                      # Not used with sqlite3.
        'PASSWORD':'<a password>',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }

It looked like originally, instead of replacing the "NAME" value, you replaced the "NAME" key (and the same for all of the other keys in the dict).

share|improve this answer
    
Thanks so much. In looking at the config file I don't even know where my brain was at. I remember thinking '' : '' looks odd. –  John Carter Dec 19 '11 at 2:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.