简体   繁体   English

从Python连接到MySQL数据库

[英]Connect to MySQL database from Python

I have a database set up in MySql Workbench and I want to connect and query the database from my python script. 我在MySql Workbench中建立了一个数据库,我想从我的python脚本连接并查询数据库。 I have no idea how to go about it. 我不知道该怎么做。

You want MySQLdb . 您需要MySQLdb

But do yourself a favour and look into one of the excellent Python wrappers/ORMs: SQLAlchemy , SQLObject , or Django . 但是请您帮个忙,并研究以下出色的Python包装器/ ORM之一: SQLAlchemySQLObjectDjango

Look at Connector/Python (written by Geert). 查看Connector / Python(由Geert编写)。 It is a pure Python implementation of the MySQL protocol, which means that it installs wherever Python installs. 它是MySQL协议的纯Python实现,这意味着它安装在Python安装的任何位置。

You can find instructions on how to install it here: http://geert.vanderkelen.org/post/164/ 您可以在此处找到有关如何安装它的说明: http : //geert.vanderkelen.org/post/164/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM