当我在django应用程序中运行python manage.py migrate时,会发生如下错误
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args,**cmd_options)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/management/base.py", line 327, in execute
self.check()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 61, in _run_checks
issues = run_checks(tags=[Tags.database])
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/core/checks/database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/home/vagrant/.pyenv/versions/3.6.3/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/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 274, in get_new_connection
conn = Database.connect(**conn_params)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args,**kwargs)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/connections.py", line 598, in connect
self._request_authentication()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/connections.py", line 862, in _request_authentication
auth_packet = self._process_auth(plugin_name, auth_packet)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/connections.py", line 933, in _process_auth
pkt = self._read_packet()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/connections.py", line 683, in _read_packet
packet.check_error()
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.OperationalError: (1045, "Access denied for user 'admin'@'localhost' (using password: NO)")
我写道 mysql -u root
,错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:no)错误发生,当我运行服务时 mysqld start
,未能启动mysqld.service:发生拒绝访问错误。此外,当我运行 service mysql stop
,未能停止mysql.service:发生拒绝访问错误。我在每个命令中添加sudo,但都会发生相同的错误。我真的不明白为什么会发生身份验证错误。我应该如何修复此错误?我的代码中有什么错误?
2条答案
按热度按时间dzjeubhm1#
你必须是
root
要运行的用户service mysqld start
或者service mysqld start
.h4cxqtbf2#
你需要使用
-p
在较新的mysql版本中,flag也在命令中:然后输入密码,您就可以登录了。
现在您可以创建一个新用户
admin
因为您将其与密码和其他权限一起使用,并且可以在settings.py文件中使用。