Home · Tags · Source Code

How to Reset MySQL Auto-Increment Values

Tags: mysql, sql, database

Last Updated on Tue, 04 Apr 2023 06:50:07 GMT - Edit Page

1- Find the current auto-increment value:

SELECT `AUTO_INCREMENT`
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '{db_name}'
AND TABLE_NAME = '{table_name}';

2- Set a new auto-increment value:

ALTER TABLE {table_name} AUTO_INCREMENT = {new_value};

Notes

The behavior of resetting the auto-increment value to a lower number depends on the storage engine used:

MyISAM:

InnoDB:

In both cases, attempting to set a lower auto-increment value does not generate an error.