gpt4 book ai didi

mysql - (2059 ,“Authentication Plugin ' caching_sha2_password'”) 在 Django 上运行与 MYSQL 数据库连接的服务器时

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:37 35 4
gpt4 key购买 nike

我想配置我的 django 项目,以便将它与 MYSQL 中的数据库连接,我使用 workbench 8.0 创建,
然后我想通过运行

来运行服务器
python manage.py runserver

来自 anaconda 命令提示符,
这样我就可以使用 Django 界面来可视化和更改数据。
请注意,我不想降级 Workbench 8.0。

这些是我所做的步骤:

从 anaconda 提示:

pip install mysqlclient

在我的项目文件夹中,settings.py

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'schema_meta',
'USER': 'root',
'PASSWORD': '<mypassword>',
'HOST': '127.0.0.1',
'PORT': '3306',
},
}

在 mysql 服务器的目录中,我打开 cnf.ini 并插入一个 [client] 部分:

[client]
database=schema_meta
host=127.0.0.1
user=root
password=<mypassword>
port=3306
default-character-set = utf8

然后从 anaconda 提示我运行

Python manage.py runserver

我得到错误

django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: Impossibile trovare il modulo specificato.\r\n")

所以我尝试通过以下线程来解决它:
django.db.utils.operationalError: (2059,"Authentication Plugin 'caching_sha2_password'")

我打开 mysql workbench 并运行此查询:

delete from mysql.user
where user='root'
and host = '127.0.0.1';
flush privileges;
CREATE USER 'root'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY '<mypassword>';

然后,在我更改的 my.ini 文件中

default-authentication-plugin= caching_sha2_password

default-authentication-plugin=mysql_native_password

最后来自 anaconda 提示符:

python manage.py runserver

但是我又明白了

django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: Impossibile trovare il modulo specificato.\r\n")

现在,怎么了?为什么它没有获取到身份验证方法的更改?

为了检查没有其他错误,从 mysql workbench,从第一个“主页” View ,我右键单击我的数据库,打开“编辑连接”,单击“测试连接”,然后软件表示连接成功。

mysql workbench saying connection successfully established

此外,我想检查问题是否出在我的 Django 设置中。所以从 anaconda 提示我运行

pip install pymysql

然后在项目文件夹中我创建了一个“connect_to_mysql.py”脚本,里面有以下代码:

import pymysql.cursors
mydb = pymysql.connect(host='127.0.0.1',
user='root',
password='<mypassword>',
db='schema_meta',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
print(mydb)

这似乎工作正常,因为当我运行时

connect_to_mysql.py 

从 python ,我得到

pymysql.connections.Connection object at 0x000002013F2851D0

我猜这意味着“连接成功建立”。
为了确保问题出在 mysql(我猜是 mysql 连接器)中,我创建了一个文件“connect_to_mysql_2.py”,其中包含以下代码:

import mysql.connector
mydb = mysql.connector.connect(user='root', password='<mypassword>',
host='127.0.0.1', database='meta_schema')
print(mydb)

当我从 anaconda 运行它时,我又得到了

"Authentication plugin '{0}' is not supported".format(plugin_name)) mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

这意味着我在 mysql workbench 和 my.ini 文件中没有修复任何问题。

如何让我的 Django 连接到我的 mysql 数据库并运行我的服务器?

有没有办法使用 pymysql 连接器而不是 mysql 连接器来建立服务器连接器?

最佳答案

这可能不是您的 python 代码中的问题,而是 python 连接器中的问题。 caching_sha2_password 插件现在是默认的 auth 插件,客户端必须支持它才能连接。因此,最好的解决方案是更新您的 python 连接器。另一种方法是禁用此插件,但我不建议这样做,因为它会降低服务器的安全性。

关于mysql - (2059 ,“Authentication Plugin ' caching_sha2_password'”) 在 Django 上运行与 MYSQL 数据库连接的服务器时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54633968/

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