What happens when auto increment primary key in MySQL comes to maximum What happens when auto increment primary key in MySQL comes to maximum mysql mysql

What happens when auto increment primary key in MySQL comes to maximum


The MySQL official documentation states that :

When the column reaches the upper limit of the data type, the next attempt to generate a sequence number fails. Use the UNSIGNED attribute if possible to allow a greater range.

And yes, you can switch the types of the auto_increment value. On this point, the documentation advises to use :

[...] the smallest integer data type for the AUTO_INCREMENT column that is large enough to hold the maximum sequence value you will need.


Yes, you can alter the table and change from INT to BIGINT without problems.

Also, you may need to change the datatype wherever it is as an FK


I would like to share a personal experience I just had about this.

Using Nagios + Check_MK + NDOUtils. NDOUtils stores all the checks in a table called nagios_servicechecks. The primary key is an auto_increment int signed.

What happens with MySQL when this limit is ranged? Well, in my case, MySQL deleted all the records but the last one. The table is now almost empty. Everytime a new record is inserted the old one is deleted.

I don't why this happens, but the fact is that I lost all my records.

IDOUtils, used with Icinga (not Nagios), fixed this issue changing int by a bigint.