Documentation Home
Connectors and APIs Manual
Download this Manual MySQLCursor.rowcount Property


count = cursor.rowcount

This read-only property returns the number of rows returned for SELECT statements, or the number of rows affected by DML statements such as INSERT or UPDATE. For an example, see Section, “MySQLCursor.execute() Method”.

For nonbuffered cursors, the row count cannot be known before the rows have been fetched. In this case, the number of rows is -1 immediately after query execution and is incremented as rows are fetched.

The rowcount property is like the mysql_affected_rows() C API function; see mysql_affected_rows().

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  Posted by Preg Match on July 16, 2015
Note that by default, buffered=False so with SELECT statements rowcount you will give you -1.
You can set buffered=True in connect(), MySQLConnection() or cursor()