sudo apt-get install Python-mysqldb
#!/usr/bin/python#-*-coding:utf-8-*-" "This file include all the common routine,that is needed inthe crawler project. Author:justnzhang @ ([email protected]) time:2014 July 28 15:03:44" "ImportOSImportSYSImportMySQLdb fromUrllibImportQuote, unquoteImportuuidreload (SYS) sys.setdefaultencoding ('Utf-8')defInsertdb (dictdata):Print "Insertdb" Printdictdata ID=uuid.uuid1 ()Try: Conn_local= MySQLdb.connect (host='192.168.30.7', user='XXX', passwd='XXX', db='XXX', port=3306) Conn_local.set_character_set ('UTF8') cur_local=conn_local.cursor () Cur_local.execute ('SET NAMES UTF8;') Cur_local.execute ('set CHARACTER set UTF8;') Cur_local.execute ('SET Character_set_connection=utf8;') Values= []#Print ValuesValues.append ("2") Values.append ("3") Values.append ("2014-04-11 00:00:00") Values.append ("2014-04-11 00:00:00") Values.append ("6") Values.append ("7") Cur_local.execute ("INSERT into health_policy values (null,%s,%s,%s,%s,%s,%s)", values)#print "invinsible seperator line-----------------------------------"Conn_local.commit () cur_local.close () Conn_local.close ( )exceptmysqldb.error,e:Print "Mysql Error%d:%s"% (E.args[0], e.args[1])if __name__=='__main__': Values= [1,2,4] Insertdb (values)
SETForeign_key_checks=0;-- ------------------------------Table structure for Health_policy-- ----------------------------DROP TABLE IF EXISTS' Health_policy ';CREATE TABLE' health_policy ' (' HID 'int( One) not NULLauto_increment, ' title 'varchar( +)DEFAULT NULLCOMMENT'Policy title', ' url 'varchar( +) not NULLCOMMENT'URL after MD5 encryption', ' Pub_time 'datetime DEFAULT NULLCOMMENT'Release Time', ' Inser_time 'datetime not NULLCOMMENT'Insertion Time', ' website 'varchar( +)DEFAULT NULLCOMMENT'Source website', ' content ' Longtext COMMENT'Policy Content', PRIMARY KEY(' hid ')) ENGINE=InnoDB auto_increment= the DEFAULTCHARSET=UTF8;
Ubuntu installation Python MySQLdb