pymysql报错:RuntimeError: ‘cryptography‘ package is ?

pymysql报错 RuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods

connection = pymysql.connect(host='localhost',
                                 user='root',
                                 password='568hdfyrtyey',
                                 database='test1')
cursor = connection.cursor()

pymysql报错:RuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods

网上很多都是指的install cryptography ,其实不然,我之前运行都好好的,突然直接就报错了,什么都没有做。

解决方案:

添加cursorclass=pymysql.cursors.DictCursor参数

connection = pymysql.connect(host='localhost',
                                 user='root',
                                 password='568hdfyrtyey',
                                 database='test1',
                                 cursorclass=pymysql.cursors.DictCursor)
cursor = connection.cursor()

第二天又遇到了问题,我需要做一些补充,

为了解决这个问题,您可以尝试手动链接一次 MySQL,然后错误就会消失。这可能是因为需要第一次生成密码的缓存。这是问题所在的根源了。

你可以是手动链接MYSQL ,或者借助工具来链接, 不过我比较懒人的方法是用编写的批处理脚本

@echo off
echo.
echo Connecting to MySQL server...
echo.

"D:\Program Files\mysql\MySQL Server 8.0\bin\mysql" -h localhost -u root -pH9MvYSqY3JmAC4aj -e "exit"

echo.
echo MySQL server disconnected.
echo.
pause


链接:https://www.zhihu.com/question/650170900/answer/3443472200
 

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值