mysql 批量插入数据过多的解决方法
发布时间:2020-12-11 23:56:05 所属栏目:MySql教程 来源:网络整理
导读:使用场景: 测试时需要插入100w的数据,跑sql脚本插入非常慢。 存储过程如下: i i ( ) innodb charset i person (name,age) (CONCAT( i i 解决方案: 1. 使用sql 生成100w数据到txt文件中。 main(String[] args) BufferedWriter writer = BufferedWriter( F
使用场景: 测试时需要插入100w的数据,跑sql脚本插入非常慢。 存储过程如下: i i () innodb charset i person (name,age) (CONCAT( ii解决方案: 1. 使用sql 生成100w数据到txt文件中。 main(String[] args) BufferedWriter writer = BufferedWriter( FileWriter( File("D:/driver/data.txt"),( i=0;i<1000000;i++(i%10==0"赵"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==1"钱"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==2"孙"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==3"李"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==4"郑"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==5"吴"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==6"周"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==7"王"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==8"张"+(i/10)+"t"+ ()(Math.random()*100)+"n"(i%10==9"刘"+(i/10)+"t"+ ()(Math.random()*100)+"n"2. 数据库中将数据导入表中: innodb charset<span style="color: #0000ff;">load data local infile <span style="color: #ff0000;">'<span style="color: #ff0000;">D:/driver/data.txt<span style="color: #ff0000;">'<span style="color: #0000ff;">into <span style="color: #0000ff;">table<span style="color: #000000;"> person(name,age); <span style="color: #0000ff;">select <span style="color: #ff00ff;">count(<span style="color: #808080;">*) <span style="color: #0000ff;">from person; 耗费时间: data local infile .067s本方案的缺点: 1.权限。 非admin用户没有导入。 2. 写文件代码。对测试人员来说,写文件不仅仅限于java,可以使用任何语言实现之。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |