Ubuntu24.04+Python3.12下卸载mysql-connector-python8.0并安装8.4
卸载旧版mysql-connector-python并安装8.4版本操作步骤
问题原因
旧版mysql-connector-python 8.0.15依赖Python的ssl.wrap_socket方法,但该方法在Python 3.12中已被移除,导致连接数据库时抛出AttributeError。升级到8.4版本可解决此兼容性问题。
操作步骤
卸载旧版本
- 若通过pip安装:
pip3 uninstall -y mysql-connector-python - 若通过系统apt包管理器安装(路径为
/usr/lib/python3/dist-packages时适用):sudo apt remove -y python3-mysql.connector
- 若通过pip安装:
安装指定版本8.4.0
使用pip3安装适配Python 3.12的8.4.0版本:pip3 install mysql-connector-python==8.4.0若系统存在多个Python版本,可指定pip3.12确保对应Python 3.12:
pip3.12 install mysql-connector-python==8.4.0验证安装结果
执行以下命令确认版本:python3 -c "import mysql.connector; print(mysql.connector.__version__)"输出应为
8.4.0,说明安装成功。
内容的提问来源于stack exchange,提问作者hossein
相关产品推荐
相关产品推荐

