我正在尝试从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
请指导我。提前谢谢。
答案 0 :(得分:-1)
您当前的用户似乎无权连接到数据库。 重新安装mysql会有所帮助 还有
'HOST': '',
'PORT': '',
将这两个字段留空