quot;cryptography is required for sha256_password or caching_sha2_passwordquot;(“sha256_password 或caching_sha2_password 需要加密)
问题描述
美好的一天.希望你一切都好.有人可以帮我解决这个问题吗?
Good day. Hope your all are well. Can someone help me with fix this?
我是 MySQL 环境的新手.我正在尝试远程连接到 MySQL 数据库.我使用了以下 python 代码并得到了这个错误.
I'm new to the MySQL environment. I'm trying to connect to MySQL Database remotely. I used the following python code and got this error.
Print(e) = "cryptography is required for sha256_password or
caching_sha2_password"
而且不知道如何解决这个错误.
And have no idea how to solve the error.
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 并尝试以这种方式连接.它对我有用,希望它也对你有用.
Download mysql connector rather than pymysql and try connecting this way. It worked for me, hope it works for u too.
这篇关于“sha256_password 或caching_sha2_password 需要加密"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“sha256_password 或caching_sha2_password 需要加密"


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01