if I have a query like the following:
INSERT INTO table (col1,col2,col3) VALUES
(\'col1_value_1\', \'col2_value_1\', \'col3_value_1\'),
(\'col1_value_2\', \'
auto_increment
is safe in concurrent environment. It's job is to give unique values, no matter how many people you have connected and working on a table. You can control the offset for incrementing, by default it's 1
.
Now what does this actually mean - it means that what's written in the table doesn't have to be incremented by 1. This is the famous "gap" problem.
Suppose that you and I are writing to your table at the same time. I wrote records 10, 11, 12
and you wrote 13, 14, 15
. However, something bad could have happened (a deadlock, or transaction failed) and my results aren't persisted - the queries failed and the auto_increment
got spent. In this scenario, your records (13, 14, 15
) are written to the disk and my aren't.
This is normal behaviour. Your table doesn't have to contain numbers that are incremented by 1. It will contain unique numbers and that's the job of auto_increment
.