这种情况,ID 是几?

表的存储引擎如果是 MyISAM,ID = 8
表的存储引擎如果是 InnoDB,ID = 6

InnoDB 表只会把自增主键的最大 ID 记录在内存中,所以重启之后会导致最大 ID 丢失

create table uuu
(
id int PRIMARY key auto_increment,
name varchar(100)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into uuu values(null, '1');
insert into uuu values(null, '2');
insert into uuu values(null, '3');
select * from uuu;

-- 重启服务
insert into uuu values(null, '4');
select * from uuu;

查询值

id  name
1	1
2	2
3	4

【Java面试题与答案】整理推荐

猜你喜欢

转载自blog.csdn.net/meism5/article/details/106796652