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