当前位置:首页 > 问答 > 正文

MySQL Python 安装MySQL-python的详细实际操作流程

MySQL | Python 安装MySQL-python 关键词:

MySQL Python 安装MySQL-python的详细实际操作流程

  1. MySQL-python驱动
  2. Python 2.7兼容性(注意:MySQL-python主要支持Python 2)
  3. 系统依赖(如Ubuntu需libmysqlclient-dev,CentOS需mysql-devel
  4. pip安装命令pip install MySQL-python
  5. 常见错误EnvironmentError: mysql_config not found(需配置系统路径或安装依赖)
  6. Windows预编译包:使用第三方库如mysqlclient替代(MySQL-python在Windows兼容性差)
  7. 替代方案:推荐mysqlclient(Python 3兼容)或PyMySQL(纯Python实现)
  8. 验证安装import MySQLdb无报错即成功
  9. 连接示例代码
    import MySQLdb  
    db = MySQLdb.connect(host="localhost", user="root", passwd="密码", db="数据库名")  
    cursor = db.cursor()  
    cursor.execute("SELECT VERSION()")  
    data = cursor.fetchone()  
    print("MySQL版本:", data)  
    db.close()  
  10. 卸载命令pip uninstall MySQL-python

注:根据【2025-07】信息,MySQL-python已逐步淘汰,建议优先考虑mysqlclientPyMySQL

MySQL Python 安装MySQL-python的详细实际操作流程

发表评论