Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django : mysql : 1045, "Access denied for user

I have the whole setup working for months on my local computer.
I'm installing on a remote site now.
Created a fresh mysql DB, and created a new user ("someuser") and gave it complete grants, like so -

GRANT ALL PRIVILEGES ON . TO 'someuser'@'localhost' IDENTIFIED BY 'somepassword' WITH GRANT OPTION;

I have sync'd the db, using "python manage.py syncdb" and the correct tables were created. My settings.py has this same user.

But when I try to login a user through the application, and it hits the DB, I see the following in the logs -

(1045, "Access denied for user 'someuser'@'localhost' (using password: YES)")

I logged in through mysql (installed on the same box as django) and checked the grants and it correctly shows -

Grants for someuser@localhost
GRANT ALL PRIVILEGES ON * . * TO 'someuser'@'localhost' IDENTIFIED BY PASSWORD '*thesaltedpasswordOverHere' WITH GRANT OPTION

I don't want to use the root user/password for django, since it doesn't seem the correct way.

Any pointers as to what might be wrong ?

like image 531
PlanetUnknown Avatar asked Mar 14 '10 19:03

PlanetUnknown


2 Answers

I do it like this for a database named foo_db:

create database foo_db;
create user foo_user identified by 'foo_password';
grant all on foo_db.* to 'foo_user'@'%';
flush privileges;
like image 183
duffymo Avatar answered Sep 18 '22 18:09

duffymo


In my case the settings.py has the following:

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'TRYDJANGO',
        'USERNAME':'user_trydjango',
        'PASSWORD':'passtry',
        'PORT':'3306',
        'HOST': 'localhost',
    }
}

And it works if I change the 'USERNAME' to 'USER':

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'TRYDJANGO',
        'USER':'user_trydjango',
        'PASSWORD':'passtry',
        'PORT':'3306',
        'HOST': 'localhost',
    }
}
like image 23
Maritza Esparza Avatar answered Sep 20 '22 18:09

Maritza Esparza