Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

django

when I used command "python manage.py makemigrations"(the same with typing "python manage.py runserver"),it threw this error.And then I checked the authority of the users. The code and result are as fllows.

mysql> select host,user from mysql.user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| %         | zhuxin        |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
| localhost | zhuxin        |
+-----------+---------------+


mysql> show grants for 'zhuxin'@'%'; 
+---------------------------------------------------------------+ 
| Grants for zhuxin@%                                           |
+---------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'zhuxin'@'%' WITH GRANT OPTION | 
| GRANT ALL PRIVILEGES ON `blogdb`.* TO 'zhuxin'@'%'            |  
+---------------------------------------------------------------+ 

mysql> show grants for 'root'@'%';
+--------------------------------------------------+
| Grants for root@%                                | 
+--------------------------------------------------+ 
| GRANT USAGE ON *.* TO 'root'@'%'                 | 
| GRANT ALL PRIVILEGES ON `blogdb`.* TO 'root'@'%' |  
+--------------------------------------------------+

I have tried everything to solve it, but for no use.

like image 396
Krimony Avatar asked Oct 07 '17 10:10

Krimony


1 Answers

You need to make changes in project settings.py. Provide USER and PASSWORD for your database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'myproject',
        'USER': 'root',
        'PASSWORD': 'rootpassword',
        'HOST': 'localhost',
        'PORT': '',
    }
}
like image 135
Astik Anand Avatar answered Sep 27 '22 18:09

Astik Anand