mysql批量导入txt文件数据
程序员文章站
2022-03-04 12:40:39
...
1、用java代码造好数据,这里就用1000条
package Utils;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class CreateMysqlData {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
FileWriter fw = new FileWriter("D:/Desktop/data.txt");
BufferedWriter bw = new BufferedWriter(fw);
for(int i=0;i<1000;i++){
String temp = String.valueOf(i);
bw.write(temp);
bw.write("\t"); //表的各个字段之间要用tab空格 隔开
bw.write("name");
bw.write("\t");
bw.write("pwd");
bw.newLine();
}
System.out.println("okay");
bw.flush();
bw.close();
fw.close();
}
}
2、cmd进入mysql命令行,进入对应的数据库
load data local infile 'D:\\Desktop\data.txt' into table user;
提示:
Query OK, 1000 rows affected (0.08 sec)
Records: 1000 Deleted: 0 Skipped: 0 Warnings: 0
到此已完成数据导入。