Oleg wrote: > SELECT LAST_INSERT_ID() You can also do it through MySQLdb. connection = MySQLdb.connect(host='host', user='user', passwd='passwd', db='database') #insert a record, then last_id = connection.db.insert_id()