Ubuntu installation Python MySQLdb

Source: Internet
Author: User
Tags md5 encryption

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.