How to quickly insert 10 million records into MySQL

How to quickly insert 10 million records into MySQL

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

insert image description here

It took 58.62 seconds to generate 1 million pieces of data, which is almost 1 minute.

insert image description here

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!

insert image description here

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:
  • Examples of 4 methods for inserting large amounts of data in MySQL
  • MYSQL batch insert data implementation code
  • Tutorial on implementing batch inserts in MySQL to optimize performance
  • How to avoid MySQL batch inserts with unique indexes
  • MySQL batch insert data script
  • Detailed explanation of MySQL batch SQL insert performance optimization
  • Solutions to MySQL batch insert and unique index problems
  • Detailed explanation of several examples of insert and batch statements in MySQL

<<:  The whole process of upgrading Angular single project to multiple projects

>>:  Web design reference firefox default style

Recommend

Learn one minute a day to use Git server to view debug branches and fix them

Debug branch During the normal development of a p...

Docker time zone issue and data migration issue

Latest solution: -v /usr/share/zoneinfo/Asia/Shan...

Use momentJs to make a countdown component (example code)

Today I'd like to introduce a countdown made ...

Troubleshooting ideas and solutions for high CPU usage in Linux systems

Preface As Linux operation and maintenance engine...

Mysql GTID Mha configuration method

Gtid + Mha + Binlog server configuration: 1: Test...

Docker data management and network communication usage

You can install Docker and perform simple operati...

Manually implement js SMS verification code input box

Preface This article records a common SMS verific...

MySQL 5.7.27 installation and configuration method graphic tutorial

MySQL 5.7.27 detailed download, installation and ...

My personal summary of mysql 5.7 database installation steps

1.mysql-5.7.19-winx64.zip (this is the free insta...

JS realizes video barrage effect

Use ES6 modular development and observer mode to ...

Detailed explanation of the new features of ES9: Async iteration

Table of contents Asynchronous traversal Asynchro...

Some conclusions on the design of portal website focus pictures

Focus images are a way of presenting content that ...

Implementation of webpack code fragmentation

Table of contents background CommonsChunkPlugin s...

Example of using Docker to build an ELK log system

The following installations all use the ~/ direct...

Example of using store in vue3 to record scroll position

Table of contents Overall Effect Listen for conta...