[Python] ‘cryptography’ package is required for sha256_password or caching_sha2_password auth methods

環境:

windows10
mysql  Ver 8.0.28
python3.7, mysql+pymysql

開發時要連線到MySQL時出錯,錯誤訊息如下:

cryptography' package is required for sha256_password or caching_sha2_password auth methods"
RuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods

去google才得知:
MySQL 自8.0+ 版本後,默認的身份認證插件由mysql_native_password 變為了caching_sha2_password,
網上提供的作法,有些答案都是去MySQL中更改默認的認證方式,但我不建議這麼做,原因就是未來部屬時,問題仍有可能會再次出現。

解決方式:

pip3 install cryptography

密碼學:
什麼是cryptography?可參考連結

發佈留言