Tag Archives: mysql executemany

MySQL Executenamy: How to Write a batch of data

Here is a simple method for you to write a batch of data in MYSQL Executenamy.
Examples:
if isinstance(item,MmzItem):
            data = {'xinxi':item['xinxi']}
            xinxia = data['xinxi']
            print(len(xinxia),type(xinxia))
            #print("ffffffffffffff",xinxi[0],xinxi[0][8])
            try:
                con.executemany('insert ignore into xi(zhi,gon,go,gon1,nian2,di2,xue2,jin2,rq2,w2z)values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',xinxia)
            except pymysql.Error as e:
                print(e)
                connect.rollback()
                connect.close()
                sys.exit(0)
            connect.commit()
            connect.close()
            #connect.commit()
            print("Saving.........................")