Pthon MySQLdb 的安装

说明:

要用python 去连接MySQL我们需要一个驱动程序这个程序就是MySQL-python,所以我们首先就是要下一个对应版本的MySQL-python (注意这个驱动程序只有32位版本的,所以你的python 环境最好也要是32位的)

第零步:下载32位的python 并安装:http://yunpan.cn/cQQnKwfeIRHq7  访问密码 def6

第一步:下载MySQLdb并安装:http://yunpan.cn/cQQtnsLcsGyEr  访问密码 6038

完成上面两步的话环境就有了、下面我们就可以写程序了。

例一:

import MySQLdb #首先要import 这个包

conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='131417',db='studio');#定义一个连接对象

cursor = conn.cursor();#得到返回的cursor对象。
cursor.execute('select * from t');#执行语句

for(x,y) in cursor:#取结果集
print 'x is %s y is %s'%(x,y);

cursor.close();#这两个都要close,以断开连接
conn.close();

原文地址:https://www.cnblogs.com/JiangLe/p/4586342.html