mysql - Django 无法连接到 MySQL

标签 mysql django python-3.x

花了几个小时找到正确的连接器来连接 MySQL 和 Django 后,我无法创建 super 用户。错误:

django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found.\r\n")

我尝试设置环境变量,settings.configure(),它表示设置已配置。数据库信息已在 settings.py 中正确输入。

Pycharm 能够连接到数据库,这是在我的 django 项目中,并且 pycharm 中的数据库标题显示 Django default。我不知道这是否意味着我的 Django 项目已连接到它,但我只是无法创建 super 用户,或者 pycharm 连接不相关。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dbname',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': 3306
    }
}

当我尝试django-admin dbshel​​l时,我收到此错误:

django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

错误中提供的两种解决方案都没有产生积极的结果。

我的最后一个问题被标记为重复,尽管解决方案不起作用,但问题在某些方面也有所不同..无论如何,下面是我尝试使用旧密码安全性时发生的情况。

重新迁移后,我让它可以使用旧身份验证。对于更新且更安全的 sha2 身份验证解决方案,我们将不胜感激。

最佳答案

更改您的 MySQL 用户密码

ALTER USER 'yourusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';

然后将您的密码放入 Django 设置文件中。希望这能解决您的问题。

关于mysql - Django 无法连接到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53896072/

相关文章:

python - 使用 Python 3 的 FTP 文本文件为空

php - 为什么给我一个 SQL 语法错误?

mysqldump : unknown option '--performance schema' error

mysql - 当 GROUP BY Id 和 DATE 时获取 COUNT 个 id

mysql - 如何将mysql备份导入mongodb?

python - 使用 Python 获取基于 IP 地址的邮政编码

python - python中tkinter输入框中的条件

python - django:从返回结果列表链接到详细信息页面

django - 使用 django_taggit 列出具有特定标签的对象

python - 带游标的嵌套 for 循环只能在 python 上获得第一个期望的结果