问题描述
我正在尝试将模型添加到数据库中,但出现错误。请解释我做错了什么。
dadi2015@ubuntu:~$ sudo python3 /home/allianceserver/myauth/manage.py migrate
[sudo] password for dadi2015:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/base/base.py",line 219,in ensure_connection
self.connect()
File "/usr/local/lib/python3.8/dist-packages/django/utils/asyncio.py",line 26,in inner
return func(*args,**kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/base/base.py",line 200,in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.8/dist-packages/django/utils/asyncio.py",**kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/MysqL/base.py",line 234,in get_new_connection
return Database.connect(**conn_params)
File "/usr/local/lib/python3.8/dist-packages/MysqLdb/__init__.py",line 130,in Connect
return Connection(*args,**kwargs)
File "/usr/local/lib/python3.8/dist-packages/MysqLdb/connections.py",line 185,in __init__
super().__init__(*args,**kwargs2)
MysqLdb._exceptions.OperationalError: (1698,"Access denied for user 'root'@'localhost'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/allianceserver/myauth/manage.py",line 22,in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py",line 401,in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py",line 395,in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py",line 330,in run_from_argv
self.execute(*args,**cmd_options)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py",line 371,in execute
output = self.handle(*args,**options)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py",line 85,in wrapped
res = handle_func(*args,**kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/commands/migrate.py",line 75,in handle
self.check(databases=[database])
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py",line 392,in check
all_issues = checks.run_checks(
File "/usr/local/lib/python3.8/dist-packages/django/core/checks/registry.py",line 70,in run_checks
new_errors = check(app_configs=app_configs,databases=databases)
File "/usr/local/lib/python3.8/dist-packages/django/core/checks/database.py",line 13,in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/MysqL/validation.py",line 9,in check
issues.extend(self._check_sql_mode(**kwargs))
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/MysqL/validation.py",in _check_sql_mode
if not (self.connection.sql_mode & {'STRICT_TRANS_TABLES','STRICT_ALL_TABLES'}):
File "/usr/local/lib/python3.8/dist-packages/django/utils/functional.py",line 48,in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/MysqL/base.py",line 376,in sql_mode
with self.cursor() as cursor:
File "/usr/local/lib/python3.8/dist-packages/django/utils/asyncio.py",line 259,in cursor
return self._cursor()
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/base/base.py",line 235,in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.8/dist-packages/django/utils/asyncio.py",in ensure_connection
self.connect()
File "/usr/local/lib/python3.8/dist-packages/django/db/utils.py",line 90,in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.8/dist-packages/django/db/backends/base/base.py",**kwargs2)
django.db.utils.OperationalError: (1698,"Access denied for user 'root'@'localhost'")
解决方法
访问数据库出现问题。首先,确保用户有权限。其次,使用 127.0.0.1 而不是 localhost。我不确定,但我遇到了类似的问题,并以这种方式解决了。
,您不应该使用 sudo
。
您可以在错误中看到数据库遇到权限问题,因为您为 mysql
提供的密码对于用户 root
不正确。 sudo
告诉 shell 以用户 root
的身份运行。