I heard that there is an interview question: How to quickly insert 10 million records into MySQL? I tried it privately and found that it took 0.9s to insert 10,000 data, 4.7s to insert 100,000 data, and about 58s to insert 1,000,000 data. For 1,000,000 data, my laptop took 5 minutes to run and stopped by itself. I was so excited that I was thinking about it. I used the following code: -- Enter the database use test; --Show all tables show tables; -- Create the majors table create table majors(id int, major varchar(255)); -- Define the end character $ delimiter "$"; -- Create a stored procedure and define a stored method create procedure batchInsert(in args int) begin declare i int default 1; -- Enable transactions (important! If not, 1 million data will take days to calculate) start transaction; while i <= args do insert into majors(id,major) value(i,concat("Software Engineering-",i)); set i = i + 1; end while; commit; end $ -- Call function to generate data -- Generate 100,000 records first, input $, and press Enter to execute call batchInsert(100000); $ It took 4.44 seconds to generate 100,000 pieces of data It took 58.62 seconds to generate 1 million pieces of data, which is almost 1 minute. Generate 10 million pieces of data. The big guys in front of the screen can try it. Haha, I killed the process with Ctrl+C! Summarize This concludes this article on how to quickly batch insert 10 million records into MySQL. For more information on how to batch insert data into MySQL, please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The whole process of upgrading Angular single project to multiple projects
>>: Web design reference firefox default style
Debug branch During the normal development of a p...
Latest solution: -v /usr/share/zoneinfo/Asia/Shan...
Today I'd like to introduce a countdown made ...
Preface As Linux operation and maintenance engine...
Gtid + Mha + Binlog server configuration: 1: Test...
You can install Docker and perform simple operati...
Preface This article records a common SMS verific...
MySQL 5.7.27 detailed download, installation and ...
1.mysql-5.7.19-winx64.zip (this is the free insta...
Use ES6 modular development and observer mode to ...
Table of contents Asynchronous traversal Asynchro...
Focus images are a way of presenting content that ...
Table of contents background CommonsChunkPlugin s...
The following installations all use the ~/ direct...
Table of contents Overall Effect Listen for conta...