1. 程式人生 > >db2快速建立千萬級模擬資料

db2快速建立千萬級模擬資料

利用python生成匯入檔案

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
path = r"F:\alien_invasion\DATA_BLKLISTS01A.del"
list = open(path,'w')
count1 = 1
print("開始執行!" )
for i in range(10000000):
    i = i+1
    count1 +=1
    randomcount = random.randint(0,9)
    print("""%s,"8613%s%08d",1,1,"remarks",""" % (i,str(randomcount),count1))
    list.writelines("""%s,"8613%s%08d",1,1,"remarks",\n""" % (i,str(randomcount),count1))
    #函式 writelines(list)函式writelines可以將list寫入到檔案中,但是不會在list每個元素後加換行符,所以如果想每行都有換行符的話需要自己再加上。
print ("執行結束!")
list.close()


利用db2 load工具匯入資料

db2 connect to  資料庫名

建立500w資料表

db2 "CREATE TABLE XIFENFEI_LOAD(col1  INT NOT NULL primary key,
                                col2  CHAR(100) NOT NULL,
                                col3  VARCHAR(20) NOT NULL,
                                col4  VARCHAR(20) NOT NULL,
                                col5  VARCHAR(20) NOT NULL)"
                               
匯入500萬資料                                                                                                                
db2 load from /tmp/DATA_BLKLISTS01.del of del insert into XIFENFEI_LOAD1 nonrecoverable


建立1000w資料表
db2 "CREATE TABLE XIFENFEI_LOAD4(col1 BIGINT  NOT NULL primary key,
                                col2  CHAR(100) NOT NULL,
                                col3  VARCHAR(20) NOT NULL,
                                col4  VARCHAR(20) NOT NULL,
                                col5  VARCHAR(20) NOT NULL)" 
匯入1000萬資料
db2 load from /tmp/DATA_BLKLISTS01A.del of del insert into XIFENFEI_LOAD4 nonrecoverable