python中mysql使用

MySQLdb使用程序

#!/bin/env python
import MySQLdb 

conn = MySQLdb.connect(host = "", user="", passwd="", port=8307, db="")
cursor = conn.cursor()
cursor.execute('set character_set_connection=utf8;')
cursor.execute('set character_set_client=utf8;')
cursor.execute('set character_set_results=utf8;')
try: cursor.execute(sql) data = cursor.fetchall() conn.commit() except MySQLdb.Error, e: print e cursor.close()

conn.commit() conn.close()
for row in data: print row

 

posted on 2015-05-12 20:04  cfox  阅读(173)  评论(0)    收藏  举报

导航