Published on

#1467 - Failed to read auto-increment value from storage engine

Authors
  • avatar
    Name
    ttyS3
    Twitter

插入数据时自增id出错了

INSERT INTO `xxxx` (`id`, `name`, `url`, `info`) VALUES (NULL, 'blahblahblah', '/xxxx', '');
#1467 - Failed to read auto-increment value from storage engine

看看表的自增id现在是多少: ```SHOW CREATE TABLE xxxx`

CREATE TABLE `xxxx` (
  `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL DEFAULT '',
  `url` varchar(255) NOT NULL DEFAULT '',
  `info` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18446744073709551615 DEFAULT CHARSET=utf8mb4

WTF ? AUTO_INCREMENT=18446744073709551615? AUTO_INCREMENT 的值已经爆掉了.

至于为什么爆掉了,原因不明. 有可能是以前从 MyISAM 转 InnoDB 的时候出问题了? 不清楚.

修正下表的自增id:

ALTER TABLE `xxxx` AUTO_INCREMENT=(SELECT MAX(id) FROM xxxx);

然后再执行插入操作就行了.

Refs: https://stackoverflow.com/a/31557413/13267147