#!/usr/bin/python import MySQLdb try: conn=MySQLdb.connect(host='localhost',user='root',passwd='yourpasswd',db='yourdb') cur=conn.cursor() cur.execute('desc bus_gps') rows=cur.fetchall() desc = cur.description name_type_dict={} for row in rows: name_type_dict[str(row[0])]=row[1] print row[0],row[1] cur.close() conn.close() print name_type_dict except MySQLdb.Error,e: print 'Mysql Error %d: %s' % (e.args[0],e.args[1])