一种使用python MySQLdb连接器禁用SSL的方法

问题描述 投票:1回答:1

使用带有python连接器的SSL打开连接会出现以下错误:

MySQLdb.connect(host ='host',user ='user,passwd ='xxx',db ='xxx',)OperationalError:(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 mysql ssl mysql-python
1个回答
0
投票

在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)

另请参见完整文档:Mysql Connector/Python Connection Arguments

如果要通过mysqlx连接,请参见Getting started with mysqlx上的示例。

© www.soinside.com 2019 - 2024. All rights reserved.