Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
MySQL Bulk Insert taking long time

I'm using python, using MySQL connector. I'm having nearly 67 Million (14GB) entries in a table. When I do a bulk insert of 2K data each time, it is taking very long to insert.

Inserted 2000 rows in 23 Seconds
Inserted 2000 rows in 25 Seconds
Inserted 2000 rows in 29 Seconds
Inserted 2000 rows in 28 Seconds

For another table (having less data), insertion speed is fine(2-4 seconds).


After using the transaction:

Inserted 2000 rows in 21 Seconds
Inserted 2000 rows in 20 Seconds
Inserted 2000 rows in 20 Seconds
Inserted 2000 rows in 18 Seconds

How can I improve the speed?


I'm using AWS RDS, Aurora MySQL version 5.7.12 (db.t3.medium) having CPU usage 4% to 8%. My objective is to insert around 50K data into a table. This table is currently having nearly 67 Million (14GB) data already. Data must need to be inserted ASAP. This almost real-time data is very important for the client. The table is having 18 columns: id(PK auto-increment), customer, serial_number, batch, data, and some others. Indexes are on (customer,serial_number) - To make the combination unique, batch - For searching, data(unique). All are by default BTREE indexed. This insertion should need to take less than 1 minute for 50K. But currently taking around 15 minutes. I've tried inserting on an empty table. It is inserting 50K data just in 5-7 seconds. As you increase the number of entries in the table, the insertion process time is increasing.

Is upgrading MySQL version is going to speed-up the insertion process anyhow? Is it the last option to split or partitioning the table? I cannot consolidate the data because each data is important, specially the last 2 years of data. Please help.

My table schema is already having some default values in 8 columns and these data are never going to update later because real-time data is very important for us. There are not many Read/Write operations are going on. Almost 2 or in some cases 3 selects per second as per RDS monitor shows.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Not an expert on MySQL, but here are few strategies you can try

  • Partitioning the table. https://dev.mysql.com/doc/refman/5.7/en/partitioning.html
  • Archive older data into separate tables if feasible. Smaller the index memory footprint, the writes will be faster
  • Give a bigger machine so that InnoDB has more memory and processing power
over 4 years ago · Santiago Trujillo Report

0

I've had the same problem with the UPDATE command - some of the delay may be attributable to Python's intrinsic speed issues, but most is likely due to mySQL and general server latencies.

I've gone "serverless" using SQLite (local db, everything in "core") and it's improved performance.

over 4 years ago · Santiago Trujillo Report

0

Depending on what your goal is there are several options you might consider. More information ultimately is useful.

If you are simply looking to free up availability you may consider using INSERT LOW PRIORITY

https://dev.mysql.com/doc/refman/5.7/en/insert.html

What type of database engine are you using?

What indexes do you have on the table? Unique indexes?

Is it possible to insert the rows with default values and run updates later asynchronously?

Are there a lot of write/read operations on that table happening at the same time?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!