MySQL – Keep an eye on your auto_increment values


In MySQL, it’s very common and recommended to you an auto_increment as Primary Key.

However that integer can have different types each having their size limitation, and they can also be signed or not.

Many people when creating a table use by default the following syntax do define their auto_increment primary key:

id int auto_increment primary key

This is a signed integer where the maximum value is 2,147,483,647.

It’s recommended as a DBA to keep an eye on how fast your tables are filling up and how much records can still be added to your tables.

And this can happen even to the bests ! (see this Github Availability Report on May 5th at 00:45)

MySQL Shell Plugin

Once again, MySQL Shell comes to the rescue with an easy plugin: ext.innodb.getAutoincFill()

The plugin returns the information related to the auto_increments fields.

Of course it’s recommended to not use the information_schema cache in the session.

It provides live information, as when the auto_increment values are exhausted…


As you can see, it’s very important to monitor the tables using auto_increments and it’s also very important to choose a right data type for them. Using unsigned is always a good practice !

MySQL Shell plugins are available here on github and contributions are welcome !

2 thoughts on “MySQL – Keep an eye on your auto_increment values

  1. INSERT IGNORE, IODKU, and many other forms of INSERT can “burn” ids. If you see that MAX(id) is a lot higher than COUNT(*), you may be having that problem.

    Normalization is a common place where you might be burning ids rapidly. To avoid it, you essentially must do a SELECT before the INSERT. At that point, “batching” the normalizations could help efficiency.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I deeply value the diversity of MySQL developers, users, community and my blog readers. I cannot agree the suffering, oppression, and systemic racism the Black community faces every day. Black lives matter.