MySQL创建千万级测试数据

一、创建临时数据表tmp_table

CREATE TABLE tmp_table (
    id INT,
    PRIMARY KEY (id)
);

 

二、构造基础数据文本  

import java.io.FileWriter;
import java.io.IOException;

public class Test2 {

    public static void main(String[] args) throws IOException {

        FileWriter fos = new FileWriter ("E:\\a.txt");
        for (int i = 20000000;i<=21500000;i++){
            fos.write(""+i);
            fos.write("\r\n");
        }
        fos.close();

    }

}

 

三、上传文件至数据库服务器home目录下

  

 

 

四、linux 登录数据库

mysql -hip  -P端口  -u用户 -p密码

use 数据库;

load data infile '/home/a.txt' replace into table tmp_table;

  

五、执行数据库插入语句

INSERT INTO `tb_alarm_record_20210901` 
SELECT
	`id`,
	floor( id / 12000 ),
	concat( '20210902_', id ),
	NULL,
	0 
FROM
	tmp_table;

  

 

posted @ 2021-09-06 15:54  跃小云  阅读(302)  评论(0编辑  收藏  举报