[Django]-Django.db.utils.OperationalError: (1045:Access denied for user 'root'@'localhost' (using password: NO)

6👍

Run the following in mysql console, to change the password encryption method to the old version in Mysql(it is changed to use cha2 in Mysql 8.0)

mysql -u root -p
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';  
FLUSH PRIVILEGES;

Then you should be free to run python manage.py migrate.

1👍

In my case it works when i typed every key in capital letter like this

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'myproj',
        'USER': 'root',
        'PASSWORD': 'password',
        'PORT': '3306',
        'HOST': 'localhost',
 }
   }

Hope atleast it helps some noob like me.

0👍

The manage.py should pick up the database access credentials from the settings.py, that’s a specific database user (and of course that user’s password as well). It’s would be a security mistake to react to this error message by granting database login privileges to the local user, god forbid to the root!

The question is rather: why Django doesn’t pick up the credentials from settings.py? In my case there were problems with the settings.py (we were restructuring our build pipeline from django pipeline to webpack) and I needed to remove pipeline related parts from my settings.py for the fix. It’s a question why I didn’t get any python error message about the settings.py problems, but instead I got this error which is not local to the real problem. That error message is just a transitive result of the source problem. Once I fixed the manage.py, the credentials were picked up from the DATABASE settings as usual and everything went smooth.

So the solution is to inspect and debug the settings.py, which is kinda hard because I don’t get message about the direct error.

0👍

For anyone stumbling across this, I was actually trying to use a password but was accidentally setting PASSWORD to None. This explained why it was saying using password: NO. Make sure your PASSWORD isn’t None.

0👍

Use the following commands

service myql stop
sudo /opt/lampp/lampp stop
sudo netstat -nap | grep :80

If apache server is running it will show you a number before "apache2" keyword
If yes write

sudo kill number
sudo /opt/lampp/lampp start

If not

sudo /opt/lampp/lampp start
👤Maheep

0👍

I solved this problem by just changing the PASSWORD field in the settings.py (DATABASES dict) to password.

0👍

If root user has password that you made. Just in setting.py change ‘PASSWORD’: to your real password. worked for me.

👤Miki

Leave a comment