gpt4 book ai didi

python - django connec mysql --_mysql_exceptions.OperationalError : (2006, )

转载 作者:行者123 更新时间:2023-11-29 07:25:23 24 4
gpt4 key购买 nike

其实我是从网站上学django的:https://docs.djangoproject.com/zh-hans/2.1/intro/tutorial02/

接下来是我的setting.py

DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_01',
'USER': 'root',
'PASSWORD': '9940',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}

MySQL : enter image description here

我想知道如何解决这个问题,或者我不知道是什么问题?非常感谢!

我认为 DATABASES 是对的,我想将 mysql 连接到名为 mysite 的 django 程序,但我运行“python manage.py migrate”:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000000003B31D08>
Traceback (most recent call last):
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\base\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\MySQLdb\__init__.py", line 85, in Connect
return Connection(*args, **kwargs)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\MySQLdb\connections.py", line 208, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2006, <NULL>)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\core\management\base.py", line 442, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\migrations\recorder.py", line 61, in applied_migrations
if self.has_table():
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\migrations\recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\base\base.py", line 255, in cursor
return self._cursor()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\base\base.py", line 232, in _cursor
self.ensure_connection()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\base\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\django\db\backends\mysql\base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\MySQLdb\__init__.py", line 85, in Connect
return Connection(*args, **kwargs)
File "D:\Tools\Anaconda3\envs\test-django\lib\site-packages\MySQLdb\connections.py", line 208, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2006, <NULL>)

最佳答案

可能是因为django不能支持mysql新的密码加密。你应该尝试改变它。您可以从 mysql 命令行客户端执行此操作:

enter image description here

关于python - django connec mysql --_mysql_exceptions.OperationalError : (2006, <NULL>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54106511/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com