pyhon MySQLdb查询出来的数据设置为字典类型

时间:2022-02-13 20:13:44

import MySQLdb
import MySQLdb.cursors

cxn=MySQLdb.Connect(host='localhost',user='root',passwd='1234',db='db_name',port=3306,\
                    cursorclass=MySQLdb.cursors.DictCursor,charset="utf8")

cur=cxn.cursor()

cur.execute("select * from tablename")

for i in cur.fetchall():

print type(i)

break;