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.數據庫表數據截圖: