多个insert时,返回第二个insert值,例如:
# 现在表里有3条记录
[root@yejr.me]> select * from t;
+----+-----+
| id | c1 |
+----+-----+
| 1 | 784 |
| 2 | 574 |
| 5 | 681 |
+----+-----+
3 rows in set (0.00 sec)
# 一次性再插入3条记录
[root@yejr.me]> insert into t values
(0,rand()*1024), (0, rand()*1024), (0,rand()*1024);
# 获取到的 last_insert_id() 值却是6,显然“不太符合预期”
[root@yejr.me]> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 6 |
+------------------+
[root@yejr.me]> select * from t;
+----+-----+
| id | c1 |
+----+-----+
| 1 | 784 |
| 2 | 574 |
| 5 | 681 |
| 6 | 841 |
| 7 | 112 |
| 8 | 87 |
+----+-----+
6 rows in set (0.00 sec)