1

I know this is an old question on lots of forums with answers suggesting to do flush privileges and reset passwords but in my case no answer has worked.

Here's the scenario:

I am able to connect to mysql via following command

mysql -u root -p -hlocalhost

I am also able to connect via python using following script

import MySQLdb
Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="root", passwd="mypass", db="mydb")
Cursor = Con.cursor()
sql = "SELECT * FROM test"
Cursor.execute(sql) #### gives 1L

But I am unable to connect via Django. Django settings.py contains

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'root',
        'PASSWD': 'mypass',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

Following is the main error

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

Please suggest.

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
comiventor
  • 3,922
  • 5
  • 50
  • 77
  • and you seriously followed all of [these](http://stackoverflow.com/a/19189930/1816093) steps ? – Drew Aug 30 '15 at 18:14
  • Try ``127.0.0.1`` not localhost. – Glyn Jackson Aug 30 '15 at 18:30
  • @Drew yes. :-( The only doubt I have is if both /usr/bin/mysqld_safe and /usr/sbin/mysqld supposed to run at the same time? while recovering root password, I had tried mysqld_safe. After that I have shutdown/restarted mysql many times. – comiventor Aug 30 '15 at 18:30
  • @GlynJackson doesn't work – comiventor Aug 30 '15 at 18:33
  • 1
    Your error says password 'NO' yet you specified a password in your OP. – Glyn Jackson Aug 30 '15 at 18:35
  • I guess you didn't follow that first step I mentioned 32 minutes ago ! – Drew Aug 30 '15 at 18:48
  • @Drew while configuring, I had copied from one of the answers provided by AlphaCentauri on the link you provided where the spelling was wrong. It went unnoticed to my eyes and then no review of the steps in any link helped. – comiventor Aug 30 '15 at 18:51

1 Answers1

2

The key for the password value in the db settings should be "PASSWORD", not "PASSWD".

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895