Under Windows to download MYSQLDB:
Http://www.codegood.com/downloads
#-*-Coding:utf-8-*-
From datetime import *
Import MySQLdb
Import Sys
File_c = "C_%d.html"
CIDS = [409070983655456980, 409070984218760117, 409070984223655957, 409070984228852701]
sql_cate = "SELECT * from tb_access_log_20140827 where id =%d"
Reload (SYS)
Sys.setdefaultencoding (' Utf-8 ')
DB_HLX = MySQLdb.connect (host= "127.0.0.1", port=3601,user= "ZCW", passwd= "ZCW", db= "Db_access_log");
Db_hlx.set_character_set (' UTF8 ')
Cur_category = Db_hlx.cursor ();
Cur_category.execute (' SET NAMES utf8; ')
Cur_category.execute (' Set CHARACTER set UTF8; ')
Cur_category.execute (' SET Character_set_connection=utf8; ')
def fetch_cate (CID):
sql_cate_x = sql_cate% (CID)
Cur_category.execute (sql_cate_x)
row = Cur_category.fetchone ()
CID = row[0]
f = open (file_c% CID, ' W ')
F.write (Row[3])
F.close ()
Def printcatelist ():
For CID in CIDS:
Fetch_cate (CID)
if __name__ = = "__main__":
Printcatelist ()
Python Query Database Small example