- import MySQLdb
- import time
- import multiprocessing as mul
- def insert():
- db=MySQLdb.connect(host='192.168.56.25', user='root', passwd='root', port=3306)
- for i in range(0,10000):
- sql='insert into dsgtest2 select * from dsgtest2 limit 100'
- cur=db.cursor()
- cur.execute('use major')
- cur.execute(sql)
- db.commit()
- time.sleep(1)
- def delete():
- db=MySQLdb.connect(host='192.168.56.25', user='root', passwd='root', port=3306)
- for i in range(0,10000):
- sql='delete from dsgtest2 limit 100'
- cur=db.cursor()
- cur.execute('use major')
- cur.execute(sql)
- db.commit()
- time.sleep(1)
- def update():
- db=MySQLdb.connect(host='192.168.56.25', user='root', passwd='root', port=3306)
- for i in range(0,10000):
- sql='update dsgtest2 set id=1 limit 100'
- cur=db.cursor()
- cur.execute('use major')
- cur.execute(sql)
- db.commit()
- time.sleep(1)
- if __name__ == "__main__":
- for i in range(25):
- j=i*3
- name='p'+str(j)
- name=mul.Process(target=insert)
- name.start()
- j += 1
- name='p'+str(j)
- name=mul.Process(target=insert)
- name.start()
- j += 1
- name='p'+str(j)
- name=mul.Process(target=insert)
- name.start()
分享一个mysql批量操作脚本
最新推荐文章于 2022-07-16 17:33:50 发布