4
CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `email` varchar(255) COLLATE utf8_bin NOT NULL,
    `password` varchar(255) COLLATE utf8_bin NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
AUTO_INCREMENT=1 ;

for example, how to get the primary key id of the last record that I insert into the table by cursor.execute("insert into ...", ...)?

apomene
  • 14,086
  • 9
  • 43
  • 68
xaero
  • 201
  • 2
  • 5
  • http://stackoverflow.com/questions/2548493/how-do-i-get-the-id-after-insert-into-mysql-database-with-python Perhaps this is what you are looking for – greperror May 30 '16 at 11:32
  • Possible duplicate of [How do I get the "id" after INSERT into MySQL database with Python?](https://stackoverflow.com/questions/2548493/how-do-i-get-the-id-after-insert-into-mysql-database-with-python) – sergiomafra May 06 '19 at 20:28

1 Answers1

7

after inserting,You can get it as: cursor.execute('select LAST_INSERT_ID()') or use cursor.lastrowid

shivsn
  • 6,820
  • 24
  • 33