简体   繁体   中英

Django (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

I have come accross a strange issue, I have deployed a django site to an Ubuntu 20.04 LTS server. The problem is my django app can not connect to the database because It is doesn't using the db connection credentials that have identified in app settings.py. It is using root with no password. But when I can run manage.py db operations without any problem.

This is my settings.py

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'pplus_db',
        'USER': 'pplus_user',
        'PASSWORD': 'dfa@4GL-5qQU',
        'HOST': 'localhost', 
        'PORT':'3306',
    }
}

The Error:

OperationalError at /accounts/login/
(1045, "Access denied for user 'root'@'localhost' (using password: NO)")
Request Method: POST
Request URL:    http://IP_ADDRESS/accounts/login/
Django Version: 3.2.5
Exception Type: OperationalError
Exception Value:    
(1045, "Access denied for user 'root'@'localhost' (using password: NO)")

I have managed to solve the problem, I think the issue was in cashing. After follow this solution django.db.utils.OperationalError: (1045:Access denied for user 'root'@'localhost' (using password: NO)

Make sure to restart your services:
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
Or if you can restart the server.

you just need to run sudo mysqld_safe --skip-grant-tables

or reset your MySQL password to null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM