我是新手,刚接触Django,我想实现django和mysql连接,并在linux环境中构建了django1.11.17和mysql8.0。
当我键入命令时
python3 manage.py makemigrations
然后输入错误
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'django1'@'localhost' (using password: NO)")
我在论坛上阅读了很多有关此错误的问题,所有人都说这是帐户和密码问题, 因此,我创建了一个数据库Firstproject,然后创建了一个新用户Django1,向django1 @%授予了Firstproject。*的所有特权,并刷新了特权。 但是设置帐户权限后,仍然会出现此问题。
关于mysql配置的Setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME':'Firstproject',
'USER':'django1',
'PASSSWORD':'asdewq',
'HOST':'localhost',
'PORT':'3306'
}
}
有关该错误的更多详细信息
Traceback (most recent call last):
File "/home/ccheng/.local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/home/ccheng/.local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ccheng/.local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 274, in get_new_connection
conn = Database.connect(**conn_params)
File "/home/ccheng/.local/lib/python3.6/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/home/ccheng/.local/lib/python3.6/site-packages/MySQLdb/connections.py", line 164, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'django1'@'localhost' (using password: NO)")
有人可以指出我错了吗?
答案 0 :(得分:0)
“ PASSSWORD”一词的拼写错误。
答案 1 :(得分:-1)
很显然,您需要正确的mysql用户名和密码。确保您已获得密码,并且所用的mysql用户具有网络访问权限,该用户可以在/etc/my.cnf中找到。祝你好运^ _ ^