"cryptography is required for sha256_password or caching_sha2_password"

"cryptography is required for sha256_password or caching_sha2_password"

美好的一天。希望你一切都好。有人可以帮我解决这个问题吗?

我是 MySQL 环境的新手。我正在尝试远程连接到 MySQL 数据库。我使用了以下 python 代码并得到了这个错误。

Print(e) = "cryptography is required for sha256_password or 
             caching_sha2_password"

并且不知道如何解决错误。

import pymysql as db

HOST = "XXXXX.XXX.XX”
PORT = XXXX
USER = "my_username"
PASSWORD = "my_password”
DB = "db_name"

try:
    connection = db.Connection(host=HOST, port=PORT,user=USER,                 
    passwd=PASSWORD, db=DB)

    dbhandler = connection.cursor()
    dbhandler.execute("SELECT * from table_name")
    result = dbhandler.fetchall()
    for item in result:
        print (DB)
 except Exception as e:
    print(e)

finally:
    connection.close()
import mysql.connector
def connection():
    conn = mysql.connector.connect(host = "XXXXX",
                  user = 'XXXXX',
                  password = 'XXXXX',
                  database = 'login_page',
                  auth_plugin='mysql_native_password')

    c = conn.cursor()
    return c , conn

下载 mysql 连接器而不是 pymysql 并尝试以这种方式连接。它对我有用,希望对你也有用。

可以使错误消息更全面、更有帮助。为了修复这个 "cryptography" 需要安装包。

pip install cryptography

要使用“sha256_password”或“caching_sha2_password”进行身份验证,您需要安装额外的依赖项:

$ python3 -m pip install PyMySQL[rsa]

来源:https://pymysql.readthedocs.io/en/latest/user/installation.html

为了它的价值,我今天在 Python 中通过 SQLAlchemy 使用 MySQL 遇到了这个问题。事实证明,我为该帐户使用了错误的密码。换句话说,如果您遇到此问题,您可能首先要确认您使用的是正确的密码。

FWIW,我不确定为什么会生成加密消息。一路上有什么问题吗?

轻松 MYSQL Workbench。创建一个新的 MySQL 用户并在 "Limit to Host Matching" 中填写您的 IP。默认是%。

enter image description here

我也遇到了这个问题。当我尝试在MySQL Worbench 中使用@brcmipn 的方法解决问题时,它告诉我MySQL 在Super Safe Mode.So 中是运行 我使用

SET GLOBAL READ_ONLY = OFF;

此后问题不再发生。

我今天在 Python 中通过 SQLAlchemy 使用 MySQL 也遇到了这个问题。它通过 mysql -u root -p 登录数据库就消失了。感谢@Ben 的提示。可能会发生一些错误。

我收到消息是因为我的数据库尚未启动。

”这个报告的意思是sha256_password和caching_sha2_password这两个加密算法需要用到密码学
虽然意思很清楚,但你可能不知道怎么解决。
其实cryptography是一个python包,所以解决方法很简单:

在您的 cmd 或终端上尝试 运行 pip install cryptography
这里是 source.