import pymysql,itertools connect = pymysql.connect( user = 'm', password = '0', db = 'x', host = 'r', port = 3306, charset = 'utf8' ) con =connect.cursor() sql="select bm from bm51 where bzz='0'" con.execute(sql) connect.commit() sha=con.fetchall() shaa=list(itertools.chain(*sha)) shaaa=[shaa[x:x+5] for x in range(0,410,5)] for i in shaaa: ii="%".join(i) print(ii) for av in i: con.execute("update bm51 set bzz='1' where bm=(%s)",(av)) connect.commit()