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

select the best presets to create full compatibility with all browsersselect

We know that the properties of the select tag in e...

Summary of the use of html meta tags (recommended)

Meta tag function The META tag is a key tag in th...

Solution to the problem that Java cannot connect to MySQL 8.0

This article shares a collection of Java problems...

Common shell script commands and related knowledge under Linux

Table of contents 1. Some points to remember 1. V...

Use of Linux cal command

1. Command Introduction The cal (calendar) comman...

Solution to the MySQL server has gone away error

MySQL server has gone away issue in PHP 1. Backgr...

Docker and portainer configuration methods under Linux

1. Install and use Docer CE This article takes Ce...

MySQL Daemon failed to start error solution

MySQL Daemon failed to start error solution A few...

How to operate Linux file and folder permissions

Linux file permissions First, let's check the...

How to use translate and transition in CSS3

I always feel that translate and transition are v...

Detailed tutorial on installing and configuring MySql5.7 on Ubuntu 20.04

Table of contents 1. Ubuntu source change 2. Inst...

Docker installation of MySQL (8 and 5.7)

This article will introduce how to use Docker to ...