Search code examples
pythonmysqlcursor

Using a cursor to access a MySQL database using Python?


I'm in the process of writing a simple Python script which grabs some data from an API and inserts it into my database. I would use a language I'm more familiar with, but as far as I'm aware, the API I'm working with is only accessible in Python.

Naturally, I'm now at the step where I need to insert the data into my database. Most documentation and references I've read seem to prefer to use the mysqldb package.

At a glance, this package appears to involve the use of cursors.

However, I've always heard that cursors are bad for a variety of reasons, mainly related to table locking, and excessive memory consumption.

Considering at the same time as this Python script will be updating my database, there will be concurrent read requests on my database, should I be using the mysqldb to access my database or not? Is there a better solution?


Solution

  • The cursor object is a required part of the Python DB API. All database library implementations will do it this way.