我刚刚开始尝试从python访问mysql,并选择使用pymysql。但是,在测试连接数据库时,我立即碰壁。代码很简单...
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pymysql
connection = pymysql.connect(host='localhost', user='root', password='nunya', db='python')
运行此代码时,我得到以下信息...
(base) [me@feynmann mysql]$ ./test-pymysql.py
Traceback (most recent call last):
File "./test-pymysql.py", line 6, in <module>
connection = pymysql.connect(host='localhost', user='root',
password='nunya', db='python')
File "/usr/local/lib/python3.7/site-packages/pymysql/__init__.py",
line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.7/site-
packages/pymysql/connections.py", line 325, in __init__
self.connect()
File "/usr/local/lib/python3.7/site-
packages/pymysql/connections.py", line 599, in connect
self._request_authentication()
File "/usr/local/lib/python3.7/site-
packages/pymysql/connections.py", line 871, in
_request_authentication
auth_packet = self._process_auth(plugin_name, auth_packet)
File "/usr/local/lib/python3.7/site-
packages/pymysql/connections.py", line 900, in _process_auth
return _auth.caching_sha2_password_auth(self, auth_packet)
File "/usr/local/lib/python3.7/site-packages/pymysql/_auth.py",
line 264, in caching_sha2_password_auth
data = sha2_rsa_encrypt(conn.password, conn.salt,
conn.server_public_key)
File "/usr/local/lib/python3.7/site-packages/pymysql/_auth.py",
line 142, in sha2_rsa_encrypt
raise RuntimeError("cryptography is required for sha256_password
or caching_sha2_password")
RuntimeError: cryptography is required for sha256_password or
caching_sha2_password
我已经进行了几次搜索,大部分时间都把我带到这里,但是似乎没有任何意义和/或解决问题的方法。
我也尝试切换到mysql.connector,但是出现了类似但更令人困惑的错误。
我知道这对你们中的大多数人来说似乎很愚蠢,但是我很感谢您提供的任何帮助。