You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python连接MySQL遇2055 SSL无可用加密套件错误求解决

解决MySQL连接报错:SSL无可用加密套件

问题原因

报错2055: 与'localhost:3306'的MySQL服务器断开连接,系统错误: 1 [SSL: NO_CIPHERS_AVAILABLE] no ciphers available,是因为mysql-connector默认尝试通过SSL连接本地MySQL,但本地MySQL未配置SSL,或Python环境的SSL套件与MySQL不兼容。

解决方案

方案1:禁用SSL连接(最简便)

在连接参数中添加ssl_disabled=True,同时修正原代码中SQL语句的拼写错误(SHOW DATABASE改为SHOW DATABASES):

from mysql.connector import connect,Error
try:
    with connect(
        host='localhost',
        user='root',
        password='455476',
        ssl_disabled=True
    ) as db:
        mycursor = db.cursor()
        mycursor.execute('SHOW DATABASES')
        for database in mycursor:
            print(database)
except Error as error:
    print(error)

方案2:配置SSL证书(需启用SSL时使用)

如果必须通过SSL连接,需确保MySQL已生成SSL证书,然后在连接时指定证书路径:

from mysql.connector import connect,Error
try:
    with connect(
        host='localhost',
        user='root',
        password='455476',
        ssl_ca='/path/to/ca.pem',
        ssl_cert='/path/to/client-cert.pem',
        ssl_key='/path/to/client-key.pem'
    ) as db:
        mycursor = db.cursor()
        mycursor.execute('SHOW DATABASES')
        for database in mycursor:
            print(database)
except Error as error:
    print(error)

替换路径为本地MySQL实际的SSL证书位置,通常在MySQL安装目录的data文件夹下(若已生成证书)。

内容的提问来源于stack exchange,提问作者alirhm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 18:33:19