MySQL auto-incrementing ID run out, how do?

 

A brief 

MySQL used in many types of self-energizing ID, ID of each increment are set an initial value. The initial value is generally from 0, and then increased by a certain step size. In MySQL as long as the byte length of the number is defined, then there will be an upper limit.
 

Second, the test

Table definition self-energizing ID, after the limit is reached.
The next time and then apply for an ID obtain the value will remain unchanged.
We can verify this by following the example here:
create table `test` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4294967295;

insert into `test` values (null);
 
 

 

Can be seen from this result, when the value of the first ID data is inserted 4294967295

When inserting data a second time, the primary key violation error is reported,
This shows that the ID value after reaching the limit, you will not be changed.
Painting words: If you anticipate ID values ​​may be used up, you should consider choosing bigint unsigned type.
 

Third, the summary

After the database table ID increment reaches the upper limit, when to apply its value would not be changed, the report will lead to a primary key violation error proceed insert data. Therefore, the design data table, try to select the appropriate field type according to business needs.
 

Guess you like

Origin www.cnblogs.com/yxhblogs/p/12041905.html