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

PySide6应用调用mysql-connector-python连接数据库时崩溃求助

PySide6应用中mysql-connector-python连接MySQL在部分PC崩溃(退出代码3221225477)

问题描述

我开发的PySide6应用使用mysql-connector-python连接私有MySQL服务器,部分PC运行正常,部分PC会直接崩溃,进程退出代码为3221225477。

调试定位的崩溃路径

经调试,崩溃根源在mysql-connector-python内部,具体路径如下:

  1. 在mainwindow.py中调用MySQL连接类:
self.mysql_db = mysql_db(self)
print("Mysql class object created")
if self.mysql_db is not None:
    if (self.mysql_db.DB_start("OUR_DB") == 1):
        self.ui.MYSQL_status_edit.setText("Connected")
        self.ui.database_edit.setText("RND_Testing")
        self.ui.MYSQL_status_edit.setStyleSheet("color: rgb(60, 179, 113);")
    else:
        self.ui.MYSQL_status_edit.setText("Disabled")
        self.ui.MYSQL_status_edit.setStyleSheet("color: rgb(255, 99, 71);")
  1. 在mysql_db.DB_start方法中发起连接:
self.mydb = mysql.connector.connect(host="server.hostname.lt",user="root",password="password",database=database,connection_timeout = timeout)
  1. mysql.connect方法在pooling.py中返回CMySQLConnection(*args, **kwargs)
  2. connection_cext.py中CMySQLConnection类的初始化逻辑:
if kwargs:
    try:
        self.connect(**kwargs)
    except Exception:
        self.close()
        raise
  1. CMySQLConnection.connect(**kwargs)调用abstract.py中的self._open_connection()
  2. _open_connection方法调用connection_cext.py的self._cmysql.connect(**cnx_kwargs)时触发崩溃。

测试验证情况

已确认崩溃PC可正常访问MySQL服务器,单独运行以下测试代码能成功连接:

import mysql.connector
from mysql.connector import Error

class mysql_db():
    def __init__(self):
        super().__init__()

    def DB_start(self,database, timeout=3):
        try:
            self.mydb = mysql.connector.connect(host="our_server.hostname.lt",user="root",password="password",database=database,connection_timeout = timeout)
        except mysql.connector.Error as err:
            print(f"mydb failed: {err}")
            return 0
        print("Connected to DB OK")
        return 1

mysql_db = mysql_db()
mysql_db.DB_start("OUR_DB")

但将相同的连接逻辑放到PySide6应用中执行时就会崩溃。

求助

恳请各位提供问题原因分析及可行的解决方案。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 04:07:36