MySQL provides the LAST_INSERT_ID() function to get the most recently inserted id for the current connection. Other connections' insertions will not be returned by this function:
LAST_INSERT_ID()
mysql> SELECT LAST_INSERT_ID(); -> 195
docs