2

Hoping someone can help me connect django to mysql db on localhost...

I have installed Django site into virtualenv folder on my desktop and following django docs Tutorial step by step.

I have mysqlclient installed via pip as per django docs.

I have WAMP V2.5 with latest phpmyadmin installed and operational.

The Django test site loads with localhost:8000 and I can easily setup a site with sqli.

Within localhost/phpmyadmin I created a blank database named 'test_db' and as an example for this question I used username = 'user' and password = 'pwd'.

My settings.py file is setup as below for the database settings:

DATABASES = {
    'default': 'django.db.backends.mysql',
    'NAME': 'test_db',
    'HOST': 'localhost',
    'PORT': '3306',
    'USERNAME': 'user',
    'PASSWORD': 'pwd',
    }
}

Once I save the settings.py script, I run the command:

python manage.py syncdb

The result I get is:

django.db.utils.OperationalError: 
(1045, "Access denied for user 'ODBC'@'localhost' (using password: YES)")

I can change the username and password to the root user and password and I still get the same result.

I have spent days on this Googling and Youtubing but nothing has helped so far... Any help appreciated.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Baz
  • 306
  • 1
  • 5
  • 12

1 Answers1

7

Change your Database settings:

'ENGINE':'django.db.backends.mysql',  
'NAME': 'test_db',  
'USER': 'root',  
'PASSWORD': '',  
'HOST': 'localhost',  
'PORT': '3306',
vabada
  • 1,738
  • 4
  • 29
  • 37
gaurav_kamble
  • 300
  • 1
  • 4
  • 8
  • Thanks gaurav_kamble... I had USERNAME instead of USER and even though I have a password setup for my localhost server, it only worked when the PASSWORD section is blank. – Baz May 14 '15 at 02:35
  • when i do this i get django.db.utils.OperationalError: (1067, "Invalid default value for 'username'") – ashim888 Jan 25 '17 at 14:09
  • @ashim888 I think you have 'username' instead of 'user' in Database settings. – gaurav_kamble Jan 28 '17 at 15:09
  • @gaurav_kamble had some issues regarding authorization. Now its working fine. – ashim888 Jan 28 '17 at 15:15