此次根据建表语句造数:
test_tab1 需要造100w数据
test_tab2 需要造1000w数据
create table test_tab1(
codeid numeric(10,0),
prov varchar(20),
city varchar(20),
country varchar(20),
name varchar(6),
birth timestamp,
comm varchar(100),
index test_tab1_idx1(city,country),
index test_tab1_idx2(name),
index test_tab1_idx3(codeid)
);
create table test_tab2(
codeid numeric(10,0),
account_id numeric(13,0),
deal_dt timestamp,
deal_type numeric(5,0),
deal_money numeric(18,3),
charge_money numeric(18,3),
lock_type numeric(1,0),
expire_time timestamp,
comms varchar(10),
index test_tab2_idx1(deal_dt),
index test_tab2_idx2(codeid)
);
借助python 的faker造数据,当然啦,数据要有一定的要求:
造数脚本
from faker import Factory
import random
import os
# 判断文件是否存在
t1 = "test_tab1.csv"
if (os.path.exists(t1)) :
#存在,则删除文件
os.remove(t1)
fake = Factory().create('zh_CN')
for i in range(1000000):
codeid = random.randint(1, 10000)
prov = fake.province()
city = fake.city_name()
country = fake.country()
name = fake.name()
birth = fake.date_object(2070-1-1)
comm = fake.pystr(min_chars=10, max_chars=18)
with open('%s'%t1, 'a', encoding='UTF-8') as fp:
fp.write("{},{},{},{},{},{},{}".format(codeid,prov,city,country,name,birth,comm))
fp.write('\n')
print('end')
fp.close()
from faker import Factory
import datetime
import random
import os
# 判断文件是否存在
t2 = "test_tab2.csv"
if (os.path.exists(t2)):
# 存在,则删除文件
os.remove(t2)
fake = Factory().create('zh_CN')
now_date = datetime.datetime.now()
data_int = int(now_date.strftime('%Y'))
startday = datetime.datetime(data_int, 1, 1)
endday = datetime.datetime(data_int, 12, 31)
diffstart = startday.toordinal() - now_date.toordinal()
diffend = endday.toordinal() - now_date.toordinal()
for i in range(1,10000001):
codeid = random.randint(1, 10000)
account_id = i
deal_dt = fake.date_between_dates(diffstart, diffend)
deal_type = random.randint(1, 100)
deal_money = random.randint(10000, 100000) + round(random.random(), 3)
charge_money = random.randint(10000, 100000) + round(random.random(), 3)
lock_type = random.randint(1, 9)
expire_time = fake.date_between_dates(diffstart+366, diffend+366)
comm = fake.pystr(min_chars=5, max_chars=10)
with open('%s' % t2, 'a', encoding='UTF-8') as fp:
fp.write("{},{},{},{},{},{},{},{},{}".format(codeid, account_id, deal_dt, deal_type, deal_money, charge_money,lock_type, expire_time, comm))
fp.write('\n')
print('end')
fp.close()