az批量update

#!/usr/bin/env python  
#coding:utf-8  
import  MySQLdb
try:     
        conn=MySQLdb.connect(host='XXXX',user='XXXXX',passwd='XXXX',db='azkaban_177',port=3306)  
        cur=conn.cursor()  
        sql="select * from user_info where cluster_info like '%fenxi%'"
        cur.execute(sql)  
        list=cur.fetchall()
        
        #print list
        for i in range(len(list)):
               #print list[i][1],list[i][4]
               print "update user_info set cluster_info='%s,ds' where username='%s';" %(list[i][4],list[i][1])
        cur.close()
        conn.close()
except MySQLdb.Error,e:  
     print 'mysql error msg:',e

猜你喜欢

转载自blog.csdn.net/mnasd/article/details/81026590
今日推荐