O'Reilly logo

MySQL for Python by Albert Lukaszewski, PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Inserting Multiple Entries

When we deal with large amounts of data that are all going into the same database, running single instances of individual INSERT commands can take a ridiculous amount of time and waste a considerable amount of I/O. What we need is a way to insert multiple items in one go.

In this chapter, we will look at the following:

  • How iteration can help us execute several individual INSERT statements rapidly
  • Using executemany() to submit several INSERT statements in one go
  • When not to use executemany()
  • Throttling how much data is inserted at a time

At the end of the chapter, we will put these lessons to use in writing a conversion program that inserts the contents of a comma-separated value (CSV) file into MySQL.

The problem ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required