2

我不明白发生了什么,我的 mysql 运行良好我使用相同的用户名和密码进行了测试连接,它可以工作,但是当我尝试连接 Django 时出现此错误。服务器也正常运行。

 Unhandled exception in thread started by <bound method Command.inner_run of     <django.contrib.staticfiles.management.commands.runserver.Command object at 0x129e0d0>>
Traceback (most recent call last):
 File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site- packages/django/core/management/commands/runserver.py", line 91, in inner_run
 self.validate(display_num_errors=True)
 File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
 File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 415, in get_server_version
self.cursor().close()
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.5-i386.egg/MySQLdb/__init__.py", line 81, in  Connect
return Connection(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.5-i386.egg/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost'   (using password: YES)")

设置.py

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

1 回答 1

2

您已在 settings.py 中正确设置了所有详细信息,您的问题似乎是,您没有localhost@root的所有权限,要获得所有权限,请运行以下命令。

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

MySQL命令提示符下,您将拥有以 root 身份访问 localhost 的所有权限。

于 2013-10-04T04:05:33.943 回答