Introducing the executemany() method

As seen in previous chapters, MySQLdb provides multiple ways to retrieve data such as: fetchall(), fetchmany(), and fetchone(). These allow us to use different strategies for processing data according to how many records we have to process and the environment in which we are working. MySQLdb also provides more than one way to insert information.

Up to now, we have used Cursor.execute() whenever we needed to insert data. As shown previously, however, executing single statements in iteration greatly increases the processing requirements of the program. For this reason, MySQL for Python provides another method for Cursor objects—executemany().

To be sure, executemany() is effectively the same as simple iteration. ...

Get MySQL for Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.