MySQLdb扩展
- https://pypi.python.org/pypi/pip#downloads 下载pip文件,然后解压,执行 python setup.py install 这是安装pip命令
- 安装wheel 在python目录下的Scripts 找到pip,然后执行 pip install wheel
- http://www.lfd.uci.edu/~gohlke/pythonlibs/ 在这里下载对应的mysqldb的 wheel文件,最好把pip目录加在path里,然后执行 pip install MySQLdb.wheel 然后就可以在程序里 import MySQLdb 了
# -*- coding:UTF-8 -*-
import MySQLdb
conn = MySQLdb.connect('47.1.1.1111', 'root', '11111', 'a', charset='utf8');
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)//默认输出list ,输出字典格式即json
cursor.execute("select * from article")
print cursor.fetchone() #取一行
print cursor.fetchall() #取所有
cur.lastrowid #插入最后一行的id