表格如下:
mysql> DESC text;
+-----------------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| text | varchar(255) | YES | | NULL | |
+-----------------+--------------+------+-----+-------------------+----------------+
2 rows in set (0.00 sec)
和 AUTO_INCREMENT 为1:
mysql> ALTER TABLE text AUTO_INCREMENT = 1;
Query OK, 1 row affected (0.36 sec)
Records: 1 Duplicates: 0 Warnings: 0
但是我很奇怪,比如:
mysql> SELECT id FROM text;
+------------+
| id |
+------------+
| 2147483647 |
+------------+
1 row in set (0.00 sec)
有什么问题?
答案 0 :(得分:1)
更改自动增量时,会将其设置为greatest(your_value,max(column)+ 1)
虽然我无法找到提及它的文档中的部分,但它在评论中
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
ALTER TABLE text AUTO_INCREMENT = 1;
然后检查
的结果SELECT `AUTO_INCREMENT`
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'DatabaseName'
AND TABLE_NAME = 'text';
确认其实际上并非1