简体   繁体   中英

Change auto_increment value on existing table in MYSQL

Is there a way to change the auto increment value? What I need is a value to be lowered because for some reason there is a bug in my database.

Two id's should match, but the auto incremented id is always one more.

Is it possible to lower it by 1 on an existing table? (MYSQL/phpmyadmin)

Yes, it is possible in MySQL. In you PhpMyAdmin select your table, go to "Operations" tab and there is "auto increment" option where you can set new auto increment value.

But remember it can break down your whole database and it's definitely not recommended to mess with auto increments.

You can reset the counter with:

For InnoDB you cannot set the auto_increment value lower or equal to the highest current index.

Note that you cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed. See How to Reset an MySQL AutoIncrement using a MAX value from another table? on how to dynamically get an acceptable value.

Source :-- stackoverflow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM