日期:2014-05-16  浏览次数:20697 次

mysql数据库中记录条数超过了bigint的最大长度,自增编号会怎么样
mysql数据库中的整型类型可以自增编号,其中bigint表示的长度最大,但是如果数据库中的记录条数超过了bigint的最大值会怎么样呢,会出现无法写入数据库的情况吗? 或者说出现这种情况该怎么解决。

------解决方案--------------------
以下是我的测试结果,供参考:

mysql> create table t(id bigint unsigned auto_increment primary key, col2 int);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values(18446744073709551613,1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values(null, 1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values(null, 1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values(null, 1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values(null, 1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+----------------------+------+
| id | col2 |
+----------------------+------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 18446744073709551613 | 1 |
+----------------------+------+
5 rows in set (0.00 sec)

mysql> show variables like '%vers%';
+-------------------------+-----------------------+
| Variable_name | Value |
+-------------------------+-----------------------+
| protocol_version | 10 |
| version | 5.0.9-beta-nt |
| version_comment | Official MySQL binary |
| version_compile_machine | ia32 |
| version_compile_os | Win32 |
+-------------------------+-----------------------+
5 rows in set (0.00 sec)

mysql>