1、数值类型
下面是整型数据
整数类型 | 字节 | 最小值 | 最大值 |
tinyint | 1 |
有符号:-128 无符号:0 |
有符号:127 无符号:255 |
smallint | 2 |
有符号:-32768 无符号:0 |
有符号:32767 无符号:65535 |
mediumint | 3 |
有符号:-8388608 无符号:0 |
有符号:8388607 无符号:1677215 |
int,integer | 4 |
有符号:-2147483648 无符号:0 |
有符号:2147483647 无符号:4294967295 |
bigint | 8 |
有符号:-9223372036854775808 无符号:0 |
有符号:9223372036854775807 无符号:很大,就不写了 |
下面是浮点数
浮点数类型 | 字节 | 最小值 | 最大值 |
float | 4 | +-1.175494351E-38 | +-3.402823466E+38 |
double | 8 | +-2.225073858E-308 | +-1.797693134E+38 |
说明:整型数据还支持在后面的小括号中指定显示的宽度,例如int(5)表示当数值宽度小于5位的时候在数字前面填满宽度,不显示指定宽度默认是int(11)
2
mysql> create table t1 (id1 int, id2 int(5)); Query OK, 0 rows affected (0.02 sec) mysql> desc t1; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id1 | int(11) | YES | | NULL | | | id2 | int(5) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> insert into t1 values(1,2); Query OK, 1 row affected (0.00 sec) mysql> select * from t1; +------+------+ | id1 | id2 | +------+------+ | 1 | 2 | +------+------+ 1 row in set (0.00 sec)
时间
mysql> create table t (d date, t time, dt datetime); Query OK, 0 rows affected (0.01 sec) mysql> desc t; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | d | date | YES | | NULL | | | t | time | YES | | NULL | | | dt | datetime | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> insert into t values (now(), now(), now()); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from t; +------------+----------+---------------------+ | d | t | dt | +------------+----------+---------------------+ | 2017-04-11 | 20:25:18 | 2017-04-11 20:25:18 | +------------+----------+---------------------+ 1 row in set (0.00 sec)
评论前必须登录!
注册