What should I do if MySQL runs out of auto-incremented IDs?

Guanhui
Release: 2020-06-03 10:42:15
Original
4139 people have browsed it

What should I do if MySQL runs out of auto-incremented IDs?

#What should I do if MySQL runs out of self-increasing IDs?

There are many types of auto-increment IDs in MySQL. Each auto-increment ID has an initial value set, and then increases according to a certain step size. As long as the byte length is defined, then there will be Upper limit. If the upper limit is reached and added again, a primary key conflict error will be reported. As a solution, consider using the "bigint unsigned" type.

Test

The auto-increment ID defined in the data table, if the upper limit is reached.

When applying for the next ID, the value obtained will remain unchanged.

We can verify it through the following example:

create table `test` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4294967295; insert into `test` values (null);
Copy after login

You can see from this result that the ID value is still 4294967295 when data is inserted for the first time.

When the data is inserted for the first time, If you insert data for the second time, a primary key conflict error will be reported.

This means that after the ID value reaches the upper limit, it will not change again.

Recommended tutorial: "MySQL Tutorial"

The above is the detailed content of What should I do if MySQL runs out of auto-incremented IDs?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!