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

如何配置SQLAlchemy使用MariaDB客户端而非MySQLdb连接MariaDB?

解决SQLAlchemy连接MariaDB时依赖MySQLdb的问题

要让SQLAlchemy改用MariaDB官方客户端连接,只需两步操作:

  • 安装MariaDB的Python驱动
    执行以下命令安装官方提供的mariadb驱动包:

    pip install mariadb
    

    若使用Python3,可对应使用pip3执行安装。

  • 调整SQLAlchemy的连接URL
    在连接字符串中明确指定使用MariaDB驱动,格式为mariadb+mariadbconnector://,修改后的代码如下:

    sqlalchemy.create_engine("mariadb+mariadbconnector://webuser:password@localhost/my_db")
    

这样SQLAlchemy就会调用MariaDB官方驱动而非MySQLdb,直接解决ModuleNotFoundError的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 12:15:35