ERROR 1467 (HY000): Failed to read auto-increment value from storage engine is raised when the MySQL storage engine (almost always InnoDB) cannot determine the current maximum AUTO_INCREMENT value for a table. The error symbol is ER_AUTOINC_READ_FAILED.
Impact
Any INSERT statement that relies on an auto-generated primary key value will fail immediately with this error. The transaction is rolled back and no row is written. Statements that supply an explicit value for the AUTO_INCREMENT column may also fail depending on the severity of the underlying problem, since InnoDB still needs to update its in-memory counter.
Applications typically surface this as a database exception during record creation. ORMs such as Hibernate, Django ORM, ActiveRecord, and SQLAlchemy will propagate it as an unchecked runtime exception, often wrapping it in a generic "could not execute statement" or "database error" message. The error is not transient — retrying the same insert will fail again until the root cause is resolved.
Common Causes
InnoDB data dictionary mismatch — After a crash or unclean shutdown, InnoDB may fail to recover the in-memory auto-increment counter, particularly on MySQL 5.x where the counter is not persisted to the redo log and must be reconstructed from the table data on startup. If that reconstruction fails, subsequent inserts raise 1467.
Table or index corruption — Physical corruption of the primary key index (clustered index in InnoDB) prevents InnoDB from scanning the maximum existing key value. This can occur after disk errors, filesystem corruption, or an abrupt server termination while a write was in progress.
AUTO_INCREMENTcounter set to an invalid value — Manually settingAUTO_INCREMENTto 0, a negative number, or a value that exceeds the column's data type maximum (e.g.,BIGINT UNSIGNEDoverflow) can put InnoDB into an inconsistent state.Partitioned table issues — On partitioned InnoDB tables, each partition maintains its own auto-increment information. Partition pruning errors or mismatches between partition definitions can prevent the counter from being read.
Tablespace or
.ibdfile is missing or inaccessible — If the per-table tablespace file (tablename.ibd) is missing, has incorrect permissions, or belongs to a different table schema, InnoDB cannot open the table at all, resulting in this error on any DML.Upgrading from MySQL 5.x to 8.x with existing tables — MySQL 8.0 changed how
AUTO_INCREMENTstate is persisted (using the redo log instead of reconstructing from data). Tables created under 5.x and imported or upgraded withoutALTER TABLE ... AUTO_INCREMENTcorrection can occasionally exhibit this issue.
Troubleshooting and Resolution Steps
Check for table errors
Run a check on the affected table first:
CHECK TABLE your_table_name;If the output shows
status: OK, the table structure is intact. Any other status indicates corruption — proceed to step 3.Inspect the current AUTO_INCREMENT value
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'your_database' AND TABLE_NAME = 'your_table_name';A
NULLresult means InnoDB could not determine the counter — confirming the error cause.Repair or rebuild the table
For a non-corrupt table where the counter is simply lost, reset it explicitly:
-- Set to a value higher than the current maximum id SELECT MAX(id) FROM your_table_name; ALTER TABLE your_table_name AUTO_INCREMENT = <max_id + 1>;If
CHECK TABLEreported corruption, attempt a repair:REPAIR TABLE your_table_name;Note:
REPAIR TABLEis not supported for InnoDB. For InnoDB, rebuild the table instead:ALTER TABLE your_table_name ENGINE = InnoDB;This performs an in-place table rebuild, reconstructing all indexes and resetting the auto-increment counter from the actual data.
Restore from backup if corruption is severe
If
ALTER TABLE ... ENGINE = InnoDBalso fails (e.g., due to missing or corrupt.ibdfile), you will need to restore the table from a known-good backup and replay any binlog events that occurred after the backup was taken.Check tablespace file permissions and presence
ls -lh /var/lib/mysql/your_database/your_table_name.ibdThe file must be owned by the
mysqluser (or whichever OS user the server runs as) and must be readable. Restore from backup or use InnoDB's tablespace import/export feature if the file is missing or belongs to a different table.After MySQL version upgrade, force counter reset
After upgrading from 5.x to 8.x, run the following on affected tables to ensure the counter is persisted in the new format:
ALTER TABLE your_table_name AUTO_INCREMENT = 1;InnoDB will silently adjust the value upward to
MAX(id) + 1if the supplied value is too low.
Additional Information
- This error carries SQLSTATE
HY000(general error), so it cannot be distinguished from other HY000 errors by SQLSTATE alone — always check the error code (1467) or symbol (ER_AUTOINC_READ_FAILED). - Related errors:
1005 (ER_CANT_CREATE_TABLE)and1030 (ER_GET_ERRNO)can accompany this error when the.ibdfile itself is missing or unreadable. - MySQL 8.0+ persists the
AUTO_INCREMENTcounter in the redo log, making it crash-safe. MySQL 5.7 and earlier reconstruct it on startup, so the counter could silently decrease after a restart if the highest-id row was deleted before the crash. - MyISAM tables store auto-increment data in the
.MYIindex file; the same symptom on a MyISAM table points to index file corruption andREPAIR TABLEis supported for that engine. - In replication setups, this error on a replica typically means the replica's copy of the table is out of sync with the source — a full table re-sync (e.g.,
mysqldump+ restore orpt-table-sync) is usually required rather than just resetting the counter.
Frequently Asked Questions
Why does this error appear only after a server restart?
On MySQL 5.7 and earlier, InnoDB does not persist the AUTO_INCREMENT counter to disk. On startup it scans the primary key index to find MAX(id) and sets the counter from that. If the index is corrupt or the scan fails, the counter cannot be initialized and any subsequent insert triggers error 1467. MySQL 8.0 fixed this by writing the counter to the redo log on every change.
Can I just use SET AUTO_INCREMENT to work around the error?
If the underlying table data and indexes are intact, yes — ALTER TABLE t AUTO_INCREMENT = N is safe and effective. If the indexes are corrupt, the ALTER itself may fail; in that case you need to rebuild the table or restore from backup.
Will REPAIR TABLE fix this on InnoDB?
No. REPAIR TABLE is a MyISAM operation. For InnoDB, the equivalent is ALTER TABLE ... ENGINE = InnoDB, which triggers a full table rebuild and implicitly reconstructs all indexes and the auto-increment counter.
How do I prevent this error in production?
Enable InnoDB checksums (on by default in MySQL 5.6+), use innodb_doublewrite = ON (default), keep regular backups, and monitor for disk-level errors. After any unclean shutdown, run CHECK TABLE on critical tables before putting the application back in service.