MySQL Connector/Python Developer Guide / ... / Connector/Python API Reference / cursor.MySQLCursor Class / MySQLCursor.lastrowid Property
Syntax:
id = cursor.lastrowid This read-only property returns the value generated for anAUTO_INCREMENT column by the previousINSERT orUPDATE statement orNone when there is no such value available. For example, if you perform anINSERT into a table that contains anAUTO_INCREMENT column,lastrowid returns theAUTO_INCREMENT value for the new row. For an example, seeSection 5.3, “Inserting Data Using Connector/Python”.
Thelastrowid property is like themysql_insert_id() C API function; seemysql_insert_id().