mysql> create table test(id int not null auto_increment primary key,name varchar(50));
Query OK, 0 rows affected (0.04 sec)mysql> insert into test values(2147483647,'hello');
Query OK, 1 row affected (0.00 sec)mysql> insert into test(name) value('cach');
ERROR 1062 (23000): Duplicate entry '2147483647' for key 'PRIMARY'有好的解决方法?

解决方案 »

  1.   

    alter table test modify id bigint auto_increment;mysql> insert into test(name) value('cach');
    Query OK, 1 row affected (0.00 sec)mysql> select * from test;
    +------------+-------+
    | id         | name  |
    +------------+-------+
    | 2147483647 | hello |
    | 2147483648 | cach  |
    +------------+-------+
    2 rows in set (0.00 sec)
      

  2.   

    alter table modify id bigint auto_increment;
    修改id数据类型就可以了。
      

  3.   

    create table test(id bigint not null auto_increment primary key,name varchar(50));
      

  4.   


    bigint从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。存储大小为 8 个字节。int从 -2^31 (-2,147,483,648) 到 2^31 - 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节。int 的 SQL-92 同义字为 integer。smallint从 -2^15 (-32,768) 到 2^15 - 1 (32,767) 的整型数据。存储大小为 2 个字节。tinyint从 0 到 255 的整型数据。存储大小为 1 字节。