执行alter语句后,MYSQL自动增量重置(mysql 5.0.92)

时间:2011-08-09 15:03:32

标签: mysql

mysql> describe phppos_sales_suspended;
+--------------+--------------+------+-----+-------------------+----------------+
| Field        | Type         | Null | Key | Default           | Extra          |
+--------------+--------------+------+-----+-------------------+----------------+
| sale_time    | timestamp    | NO   |     | CURRENT_TIMESTAMP |                |
| customer_id  | int(10)      | YES  | MUL | NULL              |                |
| employee_id  | int(10)      | NO   | MUL | 0                 |                |
| comment      | text         | NO   |     | NULL              |                |
| sale_id      | int(10)      | NO   | PRI | NULL              | auto_increment |
| payment_type | varchar(255) | YES  |     | NULL              |                |
+--------------+--------------+------+-----+-------------------+----------------+

在EMPTY表上执行以下操作后,主键似乎重置为1.为什么会这样?我以为那是不可能的。这不会发生在mysql 5.1.54

ALTER TABLE  `phppos_sales_suspended` ADD  `deleted` INT( 1 ) NOT NULL DEFAULT  '0',
ADD INDEX (  `deleted` );

mysql> describe phppos_sales_suspended;
+--------------+--------------+------+-----+-------------------+----------------+
| Field        | Type         | Null | Key | Default           | Extra          |
+--------------+--------------+------+-----+-------------------+----------------+
| sale_time    | timestamp    | NO   |     | CURRENT_TIMESTAMP |                |
| customer_id  | int(10)      | YES  | MUL | NULL              |                |
| employee_id  | int(10)      | NO   | MUL | 0                 |                |
| comment      | text         | NO   |     | NULL              |                |
| sale_id      | int(10)      | NO   | PRI | NULL              | auto_increment |
| payment_type | varchar(255) | YES  |     | NULL              |                |
| deleted      | int(1)       | NO   | MUL | 0                 |                |
+--------------+--------------+------+-----+-------------------+----------------+

1 个答案:

答案 0 :(得分:1)

向InnoDB表添加索引会重建表。不继承旧的自动增量值是一个已在新版本中修复的错误。

http://bugs.mysql.com/bug.php?id=34920

http://bugs.mysql.com/bug.php?id=21404