ps:
一般想找千万级MySQL测试数据并不容易,所以自己生成,下面这种方法优点简单,缺点耗时,需要15-20分钟;
1.pom.xml:只需要io包就够了;
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
2.Java代码段:在这里我是放在测试类中,当然也可以直接放main方法中;
(下面两种写法均行)
@RunWith(SpringRunner.class)
@SpringBootTest
public class MorningDemoApplicationTests {
@Test
public void contextLoads() throws IOException {
try {
FileWriter w = new FileWriter("D:/1.txt");
BufferedWriter bw = new BufferedWriter(w);
for (int i = 1; i <= 10000000; i++) {
String uuid = UUID.randomUUID().toString();
bw.write(i + "," + uuid + "\n");
}
bw.close();
w.close();
System.out.println("执行完毕");
}
catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void contextLoads2() throws IOException {
try {
FileOutputStream outputStream=new FileOutputStream("D:/2.txt");
for (int i = 1; i <= 10000000; i++) {
String uuid = UUID.randomUUID().toString();
StringBuffer stringBuffer=new StringBuffer();
stringBuffer.append(i).append(",").append(uuid).append("\n");
outputStream.write(stringBuffer.toString().getBytes());
}
System.out.println("执行完毕");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
3.生成文件的格式:
4.创建一个表,就存两个字段;
5.鼠标选中数据库选中刚创建的表,右键点击导入向导;
6.选择文本文件;
7.选择文件路径;
8.选择分隔符,并字段定位符选择逗号;
中间几步省略,直接下一步就行;
9.源字段对应选择;id====>1;val====>uuid;
然后一直下一步,点击开始就行;
10.数据库表数据截图: