怎么确定mysql 链接成功了呢?
asyncio.run(test_connection()) ✗ Connection failed: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods
根据你提供的错误信息,问题出现在 MySQL 的认证插件和加密连接配置上。以下是几种解决方法:
1. 安装 cryptography
包
错误信息提示需要 cryptography
包来支持 sha256_password
或 caching_sha2_password
认证方法。你可以通过以下命令安装该包:
bash
pip install cryptography
安装完成后,再次尝试连接数据库。
2. 修改用户认证插件为 mysql_native_password
如果你不想使用加密连接,可以将用户的认证插件改为 mysql_native_password
。执行以下 SQL 命令:
sql
ALTER USER 'your_username'@'your_host' IDENTIFIED WITH mysql_native_password BY 'your_password';
FLUSH PRIVILEGES;
将 your_use