MySQL problems
MySQL AUTO_INCREMENT Running Out: How Close Each Column Is, and the Fix
2 December 2026
An AUTO_INCREMENT column stops at the largest value of its type: 2,147,483,647 for a signed INT, 4,294,967,295 unsigned. When it gets there, every insert into the table fails, usually with ERROR 1062: Duplicate entry '2147483647' for key 'PRIMARY'. The fix takes hours on a large table, so it has to start weeks before.
How close every column is
SET SESSION information_schema_stats_expiry = 0;
SELECT t.table_schema, t.table_name, c.column_name, c.column_type,
t.auto_increment,
ROUND(100 * t.auto_increment /
CASE WHEN c.data_type = 'tinyint' THEN 127
WHEN c.data_type = 'smallint' THEN 32767
WHEN c.data_type = 'mediumint' THEN 8388607
WHEN c.data_type = 'int' THEN 2147483647
ELSE 9223372036854775807 END
/ IF(c.column_type LIKE '%unsigned', 2, 1), 2) AS pct_used
FROM information_schema.tables t
JOIN information_schema.columns c
ON c.table_schema = t.table_schema
AND c.table_name = t.table_name
AND c.extra LIKE '%auto_increment%'
WHERE t.auto_increment IS NOT NULL
ORDER BY pct_used DESC
LIMIT 20;
The first line matters: MySQL 8.0 caches table statistics for a day, and without it the numbers are a day old.
Why values run out faster than rows
The counter moves when a value is handed out, not when a row is kept. INSERT ... ON DUPLICATE KEY UPDATE and INSERT IGNORE can take a value and keep no row, a rolled-back insert keeps none, and bulk inserts reserve values in blocks. A table with 300 million rows can be at 2 billion. Measure the counter, not COUNT(*).
The fix, in order
- Measure the runway. Values used a day, from two readings a day apart, give the date it runs out.
- Move to BIGINT.
ALTER TABLE t MODIFY id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;changes the type, so MySQL copies the table and blocks writes while it does. On a large table use an online schema change tool such as gh-ost or pt-online-schema-change. - Change the columns that point to it. Every foreign key column that references the id must become BIGINT too, in the same change.
- Check the application. A 32-bit integer in the code fails the same way once ids pass 2,147,483,647.
- As a stopgap only: a signed INT that started at 1 has the negative half unused. It buys time and confuses everyone who sorts by id.
See it coming
Radar Engine, the detection layer of dbCove, keeps the counter of every AUTO_INCREMENT column for 30 days and works out the day it runs out, with no agent on the server:
| Detector | When it fires |
|---|---|
| Auto-increment running out | Watch when it runs out in 60 days or less, Warning in 21 days or less, Critical in 7 days or less. At 95% used, Warning if it still grows. |
The finding names the schema, table, column and type, the current value and the ceiling, the values used a day and the date it runs out. dbCove AI writes the change for that table and its foreign keys, and changes nothing without your click.
Questions
What happens when MySQL AUTO_INCREMENT reaches its maximum?
The next insert cannot get a new value and fails, usually with error 1062 Duplicate entry for the largest value of the type. Nothing can be inserted into the table until the column type is changed.
What is the maximum value of INT AUTO_INCREMENT in MySQL?
2,147,483,647 for a signed INT and 4,294,967,295 for INT UNSIGNED. BIGINT UNSIGNED goes to 18,446,744,073,709,551,615.
Can I change INT to BIGINT without downtime?
ALTER TABLE copies the table and blocks writes for the copy. gh-ost or pt-online-schema-change make the copy while writes continue and switch at the end.
Related problems
- Replication lag: a large ALTER arrives on the replica too
- All MySQL problems
- MySQL monitoring without agents
Sources
- MySQL 8.0 Reference Manual: Using AUTO_INCREMENT, AUTO_INCREMENT handling in InnoDB, Integer types, information_schema_stats_expiry