Most of the time, when inserting a piece of data, we need to know the number of its primary keys. it will automatically return the first insert at the position of the auto_increment column. Note that each time a generated id is inserted into a piece of data, we need to know its primary key, it will automatically return the value of the first occurrence of the last insert and the position of the auto_increment column.
Note that the generated id is saved on the server after each connection, this means that the value returned by the function to a given client is the first auto_increment value generated by the client after the latest statement that affects the auto_increment column.
This value will not be affected by other clients. even if they generate their own auto_increment values, this behavior ensures that we can retrieve our own IDs without worrying about the activities of other clients, no locks or other processing is required. that is to say, last_insert_id is for connection.
If we use a single insert statement to insert multiple rows, last_insert_id () only returns the value of the first row to be inserted, this makes it easy to copy the same insert statement on other servers.