日期:2014-05-16 浏览次数:20489 次
#coding:utf-8 #filename:MySQL.py #use:test to connect MySQL,and operation the MySQL datebase import MySQLdb #define some var hostname = "localhost" username = "root" password = "" dbname = "python" conn = MySQLdb.connect(host = hostname,user = username ,passwd= password,db = dbname,charset='utf8') cursor = conn.cursor() sql = "select * from test" cursor.execute(sql) row = cursor.fetchall() for a in row: for b in a: print b, print "\n"