One
Simple to delete and change the search
# coding=utf-8 "Created on May 12, 2015 @author:administrator" import mysqldbtry: #创建MySQL数据库连接, create cursor via connection conn = MYSQ Ldb.connect (host= ' 10.20.102.186 ', user= ' T8 ', passwd= ' 0889781fd27ff33096ed9123b3b4e5d6 ', port=3306, db= ' CustomerService ') cur = conn.cursor () #定义字符串变量 and assign them Adduserinfosql = "INSERT into user_info values (sy Sdate (), null,null,%s,1,1,123456,18600000001,1,1,null) "Deluserinfosql =" Delete from User_info where id=%s "SelUserI Nfosql = "SELECT * from User_info where id=%s" addcount = 0 Delcount = 0 selcount = 0 # loop adds 1000 data and determines: If the ID is not A new data is added to the data in the database, and if the ID has data in the database then the next ID is judged for I in range (1, 1001): Selcount = cur.execute (seluserinfosql% i) if (Selcount!=1): Addcount = cur.execute (adduserinfosql% i) addcount +=i # Loop Delete 1000 Data " ' For I in range (1, 1001): Cur.execute (deluserinfosql% i) ' #提交事务, close cursor, close connection conn.commit () Cur.close () Conn.close () #打印出增删改查受影响的行数 print "ExecuteAdd statement after%s row data affected "% addcount print" After executing DELETE statement%s row data affected "% delcountexcept Mysqldb.error, e:print" Mysql Error%d:%s "% ( E.args[0], e.args[1])
Ready to be perfected
Python operation MySQL database (to be perfected)