mysql中的int类型默认为有符号类型的(signed),如果数据大于2147483647,那么会被截断处理,即用默认的signed的话,最大整数只能表示到2147483647。
任何大于该值的数都会被截断为该值。所以,如果需要用到更大的整数时(如无符号整形时),必须加unsigned限定为无符号类型的。
create database fort;
use fort;
create table int_unsigned(id int(11) unsigned,name varchar(64));
create table int_default(id int(11), name varchar(64));
insert into int_unsigned values(2147483649, 'too big int number');
insert into int_default values (2147483649,'too big int number');
mysql> select * from int_default;
+------------+--------------------+
| id | name |
+------------+--------------------+
| 2147483647 | too big int number |
+------------+--------------------+
1 row in set (0.00 sec)
mysql> insert into int_unsigned values(2147483649, 'too big int number');
Query OK, 1 row affected (0.00 sec)
mysql> select * from int_unsigned;
+------------+--------------------+
| id | name |
+------------+--------------------+
| 2147483649 | too big int number |
+------------+--------------------+
1 row in set (0.00 sec)
mysql>