以前的id都是随机的,想把它们改为从1000000 auto_increment,有什么办法?

解决方案 »

  1.   

    删除这个ID列, 然后再添加ID列为 auto_increment
      

  2.   

    alter table tt drop id;
    alter table tt add id auto_increment;
    ALTER TABLE dd AUTO_INCREMENT = 1000000;
      

  3.   

    set auto_increment_offset=1000000
      

  4.   

    谢谢你的回答,但是没有解决问题,drop之后创建新表并且添加AUTO_INCREMENT之后id是从1开始的啊,怎么让它从100000开始呢。
      

  5.   


    mysql> select * from t;
    +------+------+
    | id   | c1   |
    +------+------+
    |    4 |    1 |
    |    3 |    2 |
    |   10 |    3 |
    |    1 |    4 |
    +------+------+
    4 rows in set (0.00 sec)mysql> alter table t add id int auto_increment primary key, AUTO_INCREMENT = 100;
    Query OK, 4 rows affected (0.08 sec)
    Records: 4  Duplicates: 0  Warnings: 0mysql> select * from t;
    +------+-----+
    | c1   | id  |
    +------+-----+
    |    1 | 100 |
    |    2 | 101 |
    |    3 | 102 |
    |    4 | 103 |
    +------+-----+
    4 rows in set (0.00 sec)mysql>