Mysql self-increasing id problem, how can the uninterrupted id be restored to continuous?

for example, there is a table now, and id increases itself.
has a total of 100 pieces of data. When deleting 2 pieces of data from 50 items and deleting 2 pieces of data where 80 items are deleted
how to make id continuous?

Mar.05,2022

depends on your needs, because the general self-increment id is related to joining other tables, so forced recovery of continuous self-increment is a disaster

if you ignore demand, there are two ways:

1 delete the self-incrementing field, and then rebuild

ALTER TABLE `tablename` DROP COLUMN `id`;
ALTER TABLE `tablename` ADD `id` int(10) unsigned NOT NULL AUTO_INCREMENT FIRST,ADD PRIMARY KEY (`id`), AUTO_INCREMENT = 0 ROW_FORMAT = COMPACT;

2 resets the self-incrementing field values sequentially through the sql statement

SET @i=0;
UPDATE `tablename` SET `id`=(@i:=@i+1);
ALTER TABLE `tablename` AUTO_INCREMENT=0;
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c1b1-2c2dc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c1b1-2c2dc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?