我正在尝试从 Django 应用程序连接我的 MySql 服务器,但是每当我运行命令 python manage.py runserver 时,它都会显示错误:
File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-i686.egg/MySQLdb/connections.py", line 187, in __init__
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'user'@'localhost' (using password: NO)")
但我的 settings.py 连接字符串是这样的:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'django_personnel', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'personnel', # Not used with sqlite3.
'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
但我可以很容易地从 mysql shell 连接数据库:
mysql -u root -ppersonnel django_personnel
请指导我。提前致谢。