[root@virtdb56 ~]# more mutiprocessmysql.py
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
import MySQLdb as mdb
from multiprocessing import Pool,Process
import threading
con_2 = mdb.connect('192.168.2.52','root','123456','test');
cur_2 = con_2.cursor()
def myinsert(i):
for row in range(i):
v_name = str(row)+'_'+'hao'
cur_2.execute("insert into test.t1 (id,name) values(%s,%s)",(row,v_name))
con_2.commit()
if __name__ == '__main__':
p = Pool(processes= 20)
p.apply_async(myinsert,(1000,))
p.close()
p.join()
cur_2.close()
con_2.close()
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
import MySQLdb as mdb
from multiprocessing import Pool,Process
import threading
con_2 = mdb.connect('192.168.2.52','root','123456','test');
cur_2 = con_2.cursor()
def myinsert(i):
for row in range(i):
v_name = str(row)+'_'+'hao'
cur_2.execute("insert into test.t1 (id,name) values(%s,%s)",(row,v_name))
con_2.commit()
if __name__ == '__main__':
p = Pool(processes= 20)
p.apply_async(myinsert,(1000,))
p.close()
p.join()
cur_2.close()
con_2.close()
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/91975/viewspace-2126165/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/91975/viewspace-2126165/