MySQL Unread Result with Python

Using MySQL Connector/Python, the Unread results found might happen when you use the connection object in different places without reading the result. It's not something one can go around. You can use the buffered option to read result immediately.

As mentioned in the comments, it's best to split the statements and execute them separately.

If you want to execute multiple statements, you'll need to use the multi=True option for the MySQLCursor.execute() method (since Connector/Python v1.0.4). Actually, if you don't use the multi option and send multiple statements, an InterfaceError will raise. (I do suspect a bug here as well..)

Additional remarks:

  • Instead of executing the USE-command to change databases, you can MySQLConnection.database property.
  • You best group the changes into one ALTER TABLE statement, like this:

    ALTER TABLE t1 DROP PRIMARY KEY, ADD id INT NOT NULL AUTO_INCREMENT KEY FIRST, ADD INDEX(c1)


You have to pass buffered = true in your cursor. Read more official docs

cursor = conn.cursor(buffered=True)

Tags:

Python

Mysql