sil*_*mat 9 python mysql ssl mysql-python
使用 SSL 与 python 连接器打开连接会出现以下错误:
MySQLdb.connect(host='host',user='user,passwd='xxx',db='xxx',) 操作错误:(2026,'SSL 连接错误:ASN:未知密钥 OID 类型')
当我使用 bash mysql 命令时也是如此:
mysql -p -u 用户 -h 主机 输入密码: 错误 2026 (HY000):SSL 连接错误:ASN:未知密钥 OID 类型
我发现的唯一方法是使用 --ssl-mode=DISABLED
mysql -p -u 用户 -h 主机 --ssl-mode=DISABLED 输入密码: 欢迎使用 MySQL 监视器。命令以 ; 结尾 或\g。
有什么方法可以使用 python 连接器来模拟这个吗?我在 Ubuntu 16.04 和 python 3.5.2 上使用 mysql v 5.7.26。
在 python 中不使用 SSL 连接到 mysql/mariaDB:
import mysql.connector
from mysql.connector import Error
mysql_config = {
'user': 'DB-user',
'password': 'userpassword',
'host': 'localhost',
'database': 'your-DB-name',
'port': '3306',
'ssl_disabled': True
}
try:
cnx = mysql.connector.connect(**mysql_config)
if cnx.is_connected():
print('connected to database')
except Error as e:
print("mysql DB connection error")
print(e)
Run Code Online (Sandbox Code Playgroud)
另请参阅完整文档:Mysql Connector/Python Connection Arguments。
如果您想通过 mysqlx 连接,请参阅mysqlx 入门中的示例。
| 归档时间: |
|
| 查看次数: |
14307 次 |
| 最近记录: |