本文介绍了mysql_exceptions.OperationalError:(1045,“对用户'root'@'localhost'的访问被拒绝(使用密码:是)")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用django,这是在settings.py中设置"DATABASES"后在"runserver"上出现的错误

I've started working with django, and here is the error on 'runserver' after setting up 'DATABASES' in settings.py

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

我的settings.py部分代码:

My settings.py portion of code:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'my_site',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': 'root',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }

}

我已经创建了"my_site"数据库,并且以正确的方式设置了特权(root具有所有特权).我已经使用'phpmyadmin'完成了此操作.

I've created 'my_site' database and privileges are set in the right way (root has all privileges).I've done this operations with 'phpmyadmin'.

出了什么问题?

推荐答案

在控制台中运行

mysql> grant all privileges on *.* to root@localhost identified by 'password' with grant option;

这篇关于mysql_exceptions.OperationalError:(1045,“对用户'root'@'localhost'的访问被拒绝(使用密码:是)")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:27