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

解决方案 »

  1.   

    bigint 的最大值是多少? 
    平均每秒你要消耗多少个ID? 
    这样多少年会出现你所说的情况?楼主先回答这三个问题。
      

  2.   

    真的会出现的话,那就crash! 反正N年后的事情了。 
      

  3.   


    CSDN中每天很多人会提问,提问者的知识水平并不相同。类似的问题也被提了不少次了。大多数提这个问题的人都是担心auto_increment 用完。而不是想研究或者好奇探索这个问题。如果是想研究会出现什么现象的话,则很简单,自己做个非常简单的测试(仅四句SQL)就知道了。mysql> create table t_rexuenaner929 (id bigint unsigned auto_increment primary k
    ey,col int);
    Query OK, 0 rows affected (0.11 sec)mysql> insert into t_rexuenaner929 values (18446744073709551613,1);
    Query OK, 1 row affected (0.06 sec)mysql> insert into t_rexuenaner929 values (null,1);
    Query OK, 1 row affected (0.05 sec)mysql> insert into t_rexuenaner929 values (null,1);
    ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
    mysql>
      

  4.   

    以下是我的测试结果,供参考: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>
      

  5.   

    ACMAIN_CHM
    说的很有道理,很多问题我们必须自己证实,这样才能进步。
      

  6.   

    ACMAIN_CHM
    说的很有道理,很多问题我们必须自己证实,这样才能进步。