python查询
#coding=utf-8 import MySQLdb conn = MySQLdb.Connect(host = '127.0.0.1',port=3306,user='root',passwd='',db='test',charset='utf8') cursor = conn.cursor() sql = "select * from orders" cursor.execute(sql) #获取总记录数 print cursor.rowcount #获取一条数据 rs = cursor.fetchone() print rs #获取3条数据,将从第二条开始 rs = cursor.fetchmany(3) print rs #获取所有数据,返回所有的数据 rs = cursor.fetchall() print rs cursor.close() conn.close()