Resetting AUTO_INCREMENT is taking a long time in MySQL

后端 未结 2 909
星月不相逢
星月不相逢 2021-01-18 03:10
ALTER TABLE tablename AUTO_INCREMENT = 10000000

This query is taking long time to update. Why? I need to optimize this query.

2条回答
  •  温柔的废话
    2021-01-18 03:59

    ALTER TABLE causes a rebuild of the entire table - if your table contains many rows,this can take ages.

    If you just need to bump up the value of the auto_increment value, the quickest way is to insert a dummy row (and then delete that roow if need be). This will only take a fraction of a second, whereas ALTER TABLE can take days for a large table.

    For example, suppose I have a table with an auto_increment ID column and other columns col1, col2...:

    insert into autoinc_table set ID = 10000000;
    delete from autoinc_table where ID = 10000000;
    

提交回复
热议问题