ubuntu 安裝python mysqldb

來源:互聯網
上載者:User

標籤:

sudo apt-get install python-mysqldb

#!/usr/bin/python#-*-coding:utf-8-*-‘‘‘This file include all the common routine,that are needed inthe crawler project.Author: Justnzhang @([email protected])Time:2014年7月28日15:03:44‘‘‘import osimport sysimport MySQLdbfrom urllib import quote, unquoteimport uuidreload(sys)sys.setdefaultencoding(‘utf-8‘)def insertDB(dictData):    print "insertDB"    print dictData    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 values        values.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()    except MySQLdb.Error,e:        print "Mysql Error %d: %s" % (e.args[0], e.args[1])if __name__ == ‘__main__‘:    values = [1,2,4]    insertDB(values)
SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for health_policy-- ----------------------------DROP TABLE IF EXISTS `health_policy`;CREATE TABLE `health_policy` (  `hid` int(11) NOT NULL AUTO_INCREMENT,  `title` varchar(1000) DEFAULT NULL COMMENT ‘政策標題‘,  `url` varchar(1000) NOT NULL COMMENT ‘經過MD5加密後的URL‘,  `pub_time` datetime DEFAULT NULL COMMENT ‘發布時間‘,  `inser_time` datetime NOT NULL COMMENT ‘插入時間‘,  `website` varchar(1000) DEFAULT NULL COMMENT ‘來源網站‘,  `content` longtext COMMENT ‘政策內容‘,  PRIMARY KEY (`hid`)) ENGINE=InnoDB AUTO_INCREMENT=77 DEFAULT CHARSET=utf8;

ubuntu 安裝python mysqldb

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.