How to get the current AUTO_INCREMENT value of a MySQL table
Codemia Knowledge Hub ·
Run SHOW TABLE STATUS LIKE 'table_name'; and read the Auto_increment column, or query information_schema.tables for the AUTO_INCREMENT value directly. Either way, the value is the number that will be assigned to the next new row, which is useful for previewing the next ID or debugging.
AUTO_INCREMENT is usually set on a primary key column so MySQL assigns a sequential integer to each inserted row, giving every row a unique identifier even when the input data has none.
Using SHOW TABLE STATUS
SHOW TABLE STATUS returns metadata about a table, including its AUTO_INCREMENT value:
For a table named users:
The result might look like this:
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | ... |
| users | InnoDB | 10 | Dynamic | 5 | 163.84 | 8192 | 0 | 0 | 0 | 11 | ... |
Here the next new row would get the ID 11.
Using information_schema
To get only the value, without the other status columns, query information_schema.tables:
Setting and resetting AUTO_INCREMENT
To start IDs at a specific number, use ALTER TABLE:
This makes the next ID 100.
- Increment step: MySQL does not natively support changing the increment step other than setting it globally for the server instance. You can emulate it by managing IDs manually.
- Resetting: this typically involves dropping and recreating the table, but you can also run:
This sets the next inserted value to 1, assuming no existing values are greater.
Caveats when relying on the value
- Concurrency: under high concurrency, the value you read is only a hint. Another transaction may use it before your operation completes.
- Data integrity: be careful with business logic that depends on sequential IDs, especially with replicated databases or sharded environments.
- Performance: frequent restarts or adjustments that push IDs very high can degrade performance once IDs exceed the optimized range of the column's storage type.
| Topic | Details |
| Basic Command | SHOW TABLE STATUS LIKE 'table_name'; |
| Alternative Command | SELECT AUTO_INCREMENT FROM information_schema.tables; |
| Set Initial Value | ALTER TABLE table_name AUTO_INCREMENT = value; |
| Use Case | Optimizing space, Handling unique identifiers |
| Considerations | Concurrency, Performance, Data Integrity |
Related reading
- Get first row for each partition key in Cassandra
- Get Insert Statement for existing row in MySQL
- Get list of all tables in Oracle?
- Get minimum Euclidean distance between a given vector and vectors in the database
- Get output parameter value in ADO.NET
- Get query from java.sql.PreparedStatement
- Get record counts for all tables in MySQL database
- Get records of current month
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.