使用下面的 3 个 PEM 文件,我能够成功连接到 Windows 上的 MySQL 数据库,并设置数据源。 (这里没有问题)
- 客户端密钥.pem
- 客户端证书.pem
- ca-cert.pem
但我还希望能够通过 Ubuntu 服务器 10.04 上的 Python 代码进行连接。我有 Python 和 MySQL Python 连接器设置。但正如预期的那样,尝试单独连接凭据失败,因为需要授权抛出这些 PEM 证书。
**>>>** import mysql.connector
**>>>** cnx = mysql.connector.connect(user='odbc_user', password='mypassword',host='00.00.000.000',database='mydb')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/mysql/connector/__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 95, in __init__
self.connect(**kwargs)
File "/usr/local/lib/python2.6/dist-packages/mysql/connector/abstracts.py", line 719, in connect
self._open_connection()
File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 210, in _open_connection
self._ssl)
File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 144, in _do_auth
self._auth_switch_request(username, password)
File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 177, in _auth_switch_request
**raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'odbc_user'@'hide.ec2' (using password: YES)**
**>>>**
我根据搜索尝试过但没有任何进展:
- 复制了3个.pem文件到/usr/share/ca-证书/作为.crt文件。
- Ran
sudo update-ca-certificates
将这些添加到/etc/ssl/certs/ca-certificates.crt文件。
我不是 Linux 专家,只是尝试我遇到的任何事情,所以如果有人之前做过这件事,我将非常感谢您的帮助。
答案1
>>>import mysql.connector
>>>cnx = mysql.connector.connect(user='odbc_user', password='password',host='00.00.00.000',database='database',
ssl_ca='/home/akelly/ca-cert.pem',
ssl_cert='/home/akelly/client-cert.pem',
ssl_key='/home/akelly/client-key.pem')