print"ID of last record is ", int(cursor.lastrowid) #最后插入行的主键ID
print"ID of inserted record is ", int(conn.insert_id()) #最新插入行的主键ID,conn.insert_id()一定要在conn.commit()之前,否则会返回0
MySQLdb插入后获得插入id,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/li-baibo/p/3720254.html