MySQL | Python 安装MySQL-python 关键词:
libmysqlclient-dev
,CentOS需mysql-devel
) pip install MySQL-python
EnvironmentError: mysql_config not found
(需配置系统路径或安装依赖) mysqlclient
替代(MySQL-python在Windows兼容性差) mysqlclient
(Python 3兼容)或PyMySQL
(纯Python实现) import MySQLdb
无报错即成功 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()
pip uninstall MySQL-python
注:根据【2025-07】信息,MySQL-python已逐步淘汰,建议优先考虑mysqlclient
或PyMySQL
。
本文由 司徒魁 于2025-07-29发表在【云服务器提供商】,文中图片由(司徒魁)上传,本平台仅提供信息存储服务;作者观点、意见不代表本站立场,如有侵权,请联系我们删除;若有图片侵权,请您准备原始证明材料和公证书后联系我方删除!
本文链接:https://vps.7tqx.com/wenda/477111.html
发表评论