A
A
Alex Art2020-08-12 15:05:24
MySQL
Alex Art, 2020-08-12 15:05:24

Why does insert take more than 0.01 seconds?

Good day! I installed clean CentOS 8, Mysql 8.0.17 created a simple table

CREATE TABLE IF NOT EXISTS `service`.`properties` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(150) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `name_UNIQUE` (`name` ASC) VISIBLE)
ENGINE = InnoDB

trying to insert
INSERT INTO properties (name) VALUES (1);
INSERT INTO properties (name) VALUES (2);
INSERT INTO properties (name) VALUES (3);
...

there are 10,000 records in it and ... they are inserted as much as 60 seconds. Although on my local server on macos with ssd instead of nvme they are inserted in just 2 seconds on the same mysql8. Do not tell me why and how to edit? Thank you!

Answer the question

In order to leave comments, you need to log in

6 answer(s)
F
FanatPHP, 2020-08-12
@FanatPHP

Wrap all inserts in a transaction.
To avoid confusion: the right example of how to wrap INSERTs in a transaction

S
Spartak (Web-StyleStudio), 2020-08-12
@Spartak-2205

This will be faster

INSERT INTO properties (name) VALUES 
(1), 
(2), 
(3), 
(4), 
... 
(10000);

L
Lazy @BojackHorseman MySQL, 2020-08-12
Tag

because you need to prepare a request and wrap it in a transaction

R
Ruslan Fedoseev, 2020-08-12
@martin74ua

did you set up the server? or just set?

B
BasiC2k, 2020-08-12
@BasiC2k

Remove indexes from the table, and after restore.

C
CyrusMeat, 2020-08-13
@CyrusMeat

BULK-inserts work with get_last_id, you just need to get the last id after such a batch and use the number of entries to programmatically restore the identifiers in the script. This is about optimization in general.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question